给定一个 phone 号码,我如何在 iOS 中拨打 phone 电话?
Given a phone number, how do I make a phone call in iOS?
我有一个 10 位数的 phone 号码保存在从 CloudKit 下载的字符串“3133133313”中。
我想用这个号码打电话。因此,我有Apple建议的代码。
let call = detail.value(forKey: "Phone") as? String
let url = URL(string: call!)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
很遗憾,此代码不起作用。我在这里遗漏了什么可能是显而易见的。
感谢 Leo Dabus,
我只需要为每个 phone 数字添加 "tel://" 方面。在这个项目中,我决定将此代码片段添加到我的函数中而不是我的 CloudKit 记录中。
if let call = detail.value(forKey: "Phone") as? String,
let url = URL(string: "tel://\(call)"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
我有一个 10 位数的 phone 号码保存在从 CloudKit 下载的字符串“3133133313”中。
我想用这个号码打电话。因此,我有Apple建议的代码。
let call = detail.value(forKey: "Phone") as? String
let url = URL(string: call!)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
很遗憾,此代码不起作用。我在这里遗漏了什么可能是显而易见的。
感谢 Leo Dabus,
我只需要为每个 phone 数字添加 "tel://" 方面。在这个项目中,我决定将此代码片段添加到我的函数中而不是我的 CloudKit 记录中。
if let call = detail.value(forKey: "Phone") as? String,
let url = URL(string: "tel://\(call)"),
UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}