2

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.

user5855785
  • 121
  • 6
  • 2
    This answer might be helpful for you https://stackoverflow.com/questions/4660951/how-to-use-tel-with-star-asterisk-or-hash-pound-on-ios/47062700#47062700 – Natarajan Nov 02 '18 at 10:15
  • Possible duplicate of [How to use tel: with \* (star, asterisk) or # (hash, pound) on iOS?](https://stackoverflow.com/questions/4660951/how-to-use-tel-with-star-asterisk-or-hash-pound-on-ios) – Daniel T. Nov 02 '18 at 14:40

3 Answers3

2

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)
Ali Abbas
  • 4,247
  • 1
  • 22
  • 40
0

As @Ketan Ordera suggested even after you prperaed your URL using URLEncoding, you cannot run USSD code in iOS.

Ratul Sharker
  • 7,484
  • 4
  • 35
  • 44
0

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)
    }
Diego
  • 2,395
  • 2
  • 21
  • 27