ios - 电话的 NSURL 始终为零

标签 ios iphone swift nsurl

这是我的NSURL

let url = NSURL(string: "tel://\(phoneCall)")

尽管 phoneCall 是有效的手机号码字符串,而且我正在真实的 iPhone 上进行测试,但它始终为 nil

我试过了

let url = NSURL(string: "tel:\(phoneCall)")

但它仍然nil

最佳答案

let phoneCall = "tel://9000002143";
let url:NSURL = NSURL(string:phoneCall);
    //OR
var url:NSURL = NSURL(string: "tel://9000002143")
if phoneCall == nil || phoneCall.isEmpty 
{
   print("phoneCall is empty or nil.")
}
else
{
  UIApplication.sharedApplication().openURL(url);
}

关于ios - 电话的 NSURL 始终为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33684255/

相关文章:

ios - 如何调试 "fatal error with nil while unwrapping an optional value"?

iphone - 以编程方式确定互联网速度

ios - UITableViewAutomaticDimension 不适用于自定义 XIB 单元

Swift "date from string"转换不起作用但格式适用于在线服务?

android - Ionic2 日期时间从最小日期开始

ios - 如何在处理多个任务时跟踪进度和进度 View 的增量计数?

iphone - 适用于 iOS 5 和 iOS 6 的 Facebook 集成

swift - 将图像从collectionview传递到VC

ios - 使用 CAKeyframeAnimation 延迟 UIView 的动画开始?

iphone - 用 iPhone 覆盖@media CSS