ios – UIAlertController按钮功能不起作用

ios – UIAlertController按钮功能不起作用,第1张

概述let location = CLLocationCoordinate2D(latitude: 32.075300, longitude: 34.782563) @IBAction func DirectionsTolocationButton(_ sender: Any) { // Create the AlertController and add its acti
let location =  CLLocationCoordinate2D(latitude: 32.075300,longitude: 34.782563)    @IBAction func DirectionsTolocationbutton(_ sender: Any) {        // Create the AlertController and add its actions like button in ActionSheet        let ActionSheet = UIAlertController(Title: "Please Select A Navigation Service.",message: nil,preferredStyle: .actionSheet)        let AppleMapsbutton = UIAlertAction(Title: "Apple Maps",style: .default) { action -> VoID in            let destinationname = (self.barnameTemplate )             self.openMapsAppWithDirections(to: self.Coordinatestemplate,destinationname: destinationname)            print("Apple Map Chosen!")        }        let Wazebutton = UIAlertAction(Title: "Waze",style: .default) { action -> VoID in            func openWaze(location : CLLocationCoordinate2D) {                if UIApplication.shared.canopenURL(URL(string: "waze://")!) {                    // Waze is installed. Launch Waze and start navigation                    let urlStr: String = "waze://?ll=\(location.latitude),\(location.longitude)&navigate=yes"                    UIApplication.shared.openURL(URL(string: urlStr)!)                }                else {                    // Waze is not installed. Launch AppStore to install Waze app                    UIApplication.shared.openURL(URL(string: "http://itunes.apple.com/us/app/ID323229106")!)                }            }            print("Waze Chosen!")        }

当我选择Wazebutton时没有任何反应……正如Waze在他们的API中所说的那样,我也将这个添加到我的PList中:

<key>LSApplicationQuerIEsSchemes</key><array>        <string>waze</string></array>

为什么它对我不起作用?

解决方法 你需要在函数外添加函数并调用如下.

func openWaze(location : CLLocationCoordinate2D) {                if UIApplication.shared.canopenURL(URL(string: "waze://")!) {                    // Waze is installed. Launch Waze and start navigation                    let urlStr: String = "waze://?ll=\(location.latitude),\(location.longitude)&navigate=yes"                    UIApplication.shared.openURL(URL(string: urlStr)!)                }                else {                    // Waze is not installed. Launch AppStore to install Waze app                    UIApplication.shared.openURL(URL(string: "http://itunes.apple.com/us/app/ID323229106")!)                }            }

如下调用

let Wazebutton = UIAlertAction(Title: "Waze",style: .default) { action -> VoID in            self. openWaze(location : your corrdinates)// call here your function            print("Waze Chosen!")        }
总结

以上是内存溢出为你收集整理的ios – UIAlertController按钮功能不起作用全部内容,希望文章能够帮你解决ios – UIAlertController按钮功能不起作用所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1063020.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存