26

I'm trying to initiate a call on the iPhone with the tel url that has a * in it. It properly brings up the call dialog but drops back to safari when you click call.

<a href="tel:123*12">Test</a>
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
jpiasetz
  • 1,692
  • 4
  • 21
  • 35

4 Answers4

33

This documentation from Apple should be helpful:

To prevent users from maliciously redirecting phone calls or changing the behavior of a phone or account, the Phone application supports most, but not all, of the special characters in the tel scheme. Specifically, if a URL contains the * or # characters, the Phone application does not attempt to dial the corresponding phone number.

UPDATE (Jan 2, 2018): The information mentioned here may be outdated. Please refer to new documentation if Apple has relaxed these rules in their newer SDKs. Refer to Husam's answer.

Mahesh
  • 34,573
  • 20
  • 89
  • 115
  • 1
    **iOS 11 allows calling `*` or `#`**, read my answer here https://stackoverflow.com/a/47062700/1599713 – Husam Dec 25 '17 at 22:25
11

iOS11 now allows us to call number with * or #


Swift Example code

    let number = "*111*12345#"
    let app = UIApplication.shared
    if let encoded = number.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) {
        let u = "tel://\(encoded)"
        if let url = URL(string:u) {
            if app.canOpenURL(url) {
                app.open(url, options: [:], completionHandler: { (finished) in

                })
                return
            }
        }
    }
Husam
  • 8,149
  • 3
  • 38
  • 45
  • How? Using iOS11, Xcode 9.2, Swift 4.0.3, I'm unable to dial a number with # and *. – leanne Dec 25 '17 at 22:18
  • Thanks, Husam! I was encoding the entire string (tel://*111*12345#). The key was to *only* encode the *number*, not the `tel://` prefix. – leanne Dec 25 '17 at 22:35
5

The approved answer is not correct, at least anymore. I've tested both as a web page and in app being able to dial using the special character # and *. What you do have to do if you wish to use those characters in either instance though is to encode them.

In HTML, # becomes %23 and * does not need to be escaped

If using Swift, you can encode your link and press it from an app using this function:

//number format example (commas are pauses): 123-456-7890,,555#,1234
fileprivate func callNumber(_ number: String) {
    let dialString = "telprompt://" + number
    if let escapedDialString = dialString.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) {
      if let dialURL = URL(string: escapedDialString) {
        UIApplication.shared.openURL(dialURL)
      }
    }
  }
sschale
  • 5,168
  • 3
  • 29
  • 36
  • can we open dial pad from my app. string like *123456#. I have tried with above answers, but its not working. Please help me its very urgent. – Akshada-Systematix Jun 07 '17 at 12:53
  • See [@Husam's answer](https://stackoverflow.com/a/47062700/1107226). Husam's example code does, indeed, work on iOS 11. The trick is to encode *only* the number portion, not the `tel://` portion. (Also not that `telprompt://` is no longer needed to get the call confirmation prompt. `tel://` will now do the same.) – leanne Dec 25 '17 at 22:54
  • I think you just need .open() not .openURL – Jason Apr 26 '18 at 22:49
0

If you want to add * to href typed as "tel" you need to use the utf-8 encoded version - %2A

Reference : W3

For example

<a href="tel:%2A1234"> Phone me <a/>