我想在 iOS 应用程序中制作一个调用按钮,该按钮会提示 native 调用弹出窗口,其中包含我提供的号码。
这是我现在的代码:
@IBAction func btnCall(sender : AnyObject) {
UIApplication .sharedApplication() .openURL(url: "tel://0000000000")
}
这是我遇到的错误:
Cannot convert the expression's type 'Bool' to type 'NSURL!'
最佳答案
openURL
方法需要一个 NSURL
对象,而您正在那里传递一个字符串。这就是它不起作用的原因。
使用NSURL
类方法:
class func URLWithString(_ URLString: String!)
例子
UIApplication.sharedApplication().openURL(url: NSURL(string:"tel:0000000000"))
请注意,URL 架构也是 tel:
而不是 tel://
。
关于ios - 从 iOS 应用调用号码 : Cannot convert the expression's type 'Bool' to type 'NSURL!' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25021852/