I am using the below code in Swift 4.x:
let url = URL(string: "tel://*#06#")
This gives url as nil. Just this particular number has some problem. Can someone tell me how to solve this and why is this even a problem in the first place.
I am using the below code in Swift 4.x:
let url = URL(string: "tel://*#06#")
This gives url as nil. Just this particular number has some problem. Can someone tell me how to solve this and why is this even a problem in the first place.
According to apple documentation here :
To prevent users from maliciously redirecting phone calls or changing the behavior of a phone or account, the Phone app supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone app does not attempt to dial the corresponding phone number.
Please note that for other characters, you can use addingPercentEncoding
method to escape special characters which returns a properly escaped version of your original string.
Example:
let encoding = phoneNumberString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)
As @Ketan Ordera suggested even after you prperaed your URL using URLEncoding, you cannot run USSD code in iOS.
To make a call use the next function:
static func callPhone (phone:String){
guard let number = URL(string: "telprompt://" + phone) else { return }
UIApplication.shared.open(number)
}