ios - 从 iOS 应用调用号码 : Cannot convert the expression's type 'Bool' to type 'NSURL!'

标签 ios iphone swift

我想在 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/

相关文章:

ios - 当用户 ios 已接受位置权限时,再次请求用户位置权限

ios - 使用 FacebookSDK 在 Facebook 上仅共享文本的问题

ios - 如何显示一个 ViewController 然后关闭它以显示一个 UISplitViewController?

ios - 使用 AlamoFire 在 Swift 中通过证书固定实现的 HTTPS 请求失败

ios - 在 Swift 中获取图像名称 UIImagePickerController

objective-c - 检查NSString是否包含全部或某些字符

objective-c - Objective-C : Adding Loading View to View Controllers

ios - 启动 App 时 Mvvmcross 颜色插件抛出错误

ios - 如何在用户返回主屏幕后每次重新启动 iOS 应用程序?

swift - 如何更改 SpriteNode 中图像的色调