[英]Prompt when trying to dial a phone number using tel:// scheme on iOS 10.3
[英]tel:// scheme automatically formats the phone number
我尝试使用此示例号码 639450200901 拨打电话,但似乎 iOS sdk 会自动格式化电话号码。 在警报上显示这样一个“+63 945 020 0901”。 有什么建议不要自动格式化,我想在没有这个 + 号的情况下继续通话吗? 这是我的示例代码:
if let phoneNum = _params["recipient"] as? String,
let percentEncodedString = phoneNum.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed),
let url = URL(string: "tel:\(percentEncodedString)") {
if (UIApplication.shared.canOpenURL(url)) {
UIApplication.shared.open(phoneNumUrl, options: [:], completionHandler: { ( completed ) in
print("Call completed")
}
}
如 10.3 发行说明中所述。
https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-10.3/
打开网址
当第三方应用程序在 tel://、facetime:// 或 facetime-audio:// URL、iOS 上调用 openURL:时,会显示提示并要求用户在拨号前确认。
因此,当您使用方案 tel:// 调用 URL 时,电话号码将由操作系统格式化,并显示在提示符中。 这是一个系统提示,我们对此无能为力。
但是,您可以在显示系统提示之前创建自定义警报并以所需格式显示 phoneNumber:
if let phoneNumber = phoneNumber, let phoneURL = NSURL(string: ("tel://" + phoneNumber)) {
let alert = UIAlertController(title: ("Call " + phoneNumber + "?"), message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Call", style: .default, handler: { (action) in
UIApplication.shared.open(phoneURL as URL, options: [:], completionHandler: nil)
}))
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alert, animated: true, completion: nil)
}
有关电话链接的更多信息,请查看: Apple URL 方案参考
您可以在此处找到有关电话呼叫 URL 的更多详细信息,以及移动操作系统在RFC 2806解析电话 URL 时如何格式化电话号码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.