简体   繁体   English

tel:// 方案自动格式化电话号码

[英]tel:// scheme automatically formats the phone number

I trying to make a phone call with this sample number 639450200901 but it seems iOS sdk automatically formats the phone number.我尝试使用此示例号码 639450200901 拨打电话,但似乎 iOS sdk 会自动格式化电话号码。 Displaying like this one "+63 945 020 0901" on the alert.在警报上显示这样一个“+63 945 020 0901”。 Any suggestions for this not to be automatically formatted, i wanted to proceed with the call without this + sign?有什么建议不要自动格式化,我想在没有这个 + 号的情况下继续通话吗? Here is my sample code:这是我的示例代码:

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")
            }
    }

As stated in the 10.3 release notes.如 10.3 发行说明中所述。

https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-10.3/ https://developer.apple.com/library/content/releasenotes/General/RN-iOSSDK-10.3/

openURL打开网址

When a third party application invokes openURL: on a tel://, facetime://, or facetime-audio:// URL, iOS displays a prompt and requires user confirmation before dialing.当第三方应用程序在 tel://、facetime:// 或 facetime-audio:// URL、iOS 上调用 openURL:时,会显示提示并要求用户在拨号前确认。

So, when you invoke a URL with scheme tel://, phoneNumber will be formatted by the OS, and shown in the prompt.因此,当您使用方案 tel:// 调用 URL 时,电话号码将由操作系统格式化,并显示在提示符中。 It's a system prompt and we can't do anything about it.这是一个系统提示,我们对此无能为力。

You may however create a custom alert and show phoneNumber in your desired format before the system prompt is shown:但是,您可以在显示系统提示之前创建自定义警报并以所需格式显示 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)
}

For more info on phone links, please check: Apple URL Scheme Reference有关电话链接的更多信息,请查看: Apple URL 方案参考

You may find more details on URLs for Telephone Calls, how phone numbers are formatted when a telephone URL is being parsed by the mobile OS here RFC 2806 .您可以在此处找到有关电话呼叫 URL 的更多详细信息,以及移动操作系统在RFC 2806解析电话 URL 时如何格式化电话号码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM