【问题标题】:iOS canOpenURL fails for phone dialingiOS canOpenURL 电话拨号失败
【发布时间】:2014-09-27 23:17:31
【问题描述】:

尽我所能,我无法获得一个简单的应用程序来拨打号码。

我为这个函数绑定了一个按钮动作:

@IBAction func wackAMole(sender: AnyObject) {
    var phoneNumber = "tel://555-555-5555"
    var url = NSURL(fileURLWithPath: phoneNumber)
    var sharedApplication = UIApplication.sharedApplication()
    if (sharedApplication.canOpenURL(url)) {
        sharedApplication.openURL(url)
    }
}

我还向 Info.plist 添加了“电话”作为“必需的设备功能”仍然无济于事。在 iPhone 5 上的调试器下运行时,canOpenURL() 返回 false。

即使我将 phoneNumber 更改为“https://google.com”,canOpenURL() 也会返回 false。

有什么想法可以看下一步吗?

【问题讨论】:

    标签: ios iphone swift


    【解决方案1】:

    您没有为本地文件系统条目创建 URL,因此您不应使用 fileURLwithPath。你应该使用URLWithString -

    var url = NSURL.URLWithString(phoneNumber)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-25
      • 1970-01-01
      • 2020-09-17
      • 1970-01-01
      相关资源
      最近更新 更多