I trying to make a phone call with this sample number 639450200901 but it seems iOS sdk automatically formats the phone number. Displaying like this one "+63 945 020 0901" on the alert. 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.
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.
So, when you invoke a URL with scheme tel://, phoneNumber will be formatted by the OS, and shown in the prompt. 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:
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
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.