URL with string tel://*#06# is returning nil in Swift


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.

Ali Abbas

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.


let encoding = phoneNumberString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at


Login to comment