UIAlertController按钮功能不起作用 [英] UIAlertController button function not working
本文介绍了UIAlertController按钮功能不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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中说iv将它添加到我的Plist中:
When i choose WazeButton nothing happens... as Waze says in their API iv added this to my Plist as well :
<key>LSApplicationQueriesSchemes</key>
<array>
<string>waze</string>
</array>
为什么它不适合我?
why it doesn't work for me?
推荐答案
您需要在函数外添加函数并调用,如下所示。
You need to add function out side the function and call as below.
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")!)
}
}
呼叫如下
Calling as below
let WazeButton = UIAlertAction(title: "Waze", style: .default) { action -> Void in
self. openWaze(location : your corrdinates)// call here your function
print("Waze Chosen!")
}
这篇关于UIAlertController按钮功能不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文