![](/img/trans.png)
[英]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.