1

I want to call phone number "#51234" in Xcode use telprompt.

but telprompt is reject it.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://#5%@", nzoneNum]]];

nzomeNum is "1234"

Cœur
  • 37,241
  • 25
  • 195
  • 267
Mr_T
  • 9
  • 4

2 Answers2

3

At least as of iOS 11, one can dial numbers with a hashtag (#) or asterisk (*).

Make calls with these characters by first encoding the phone number, then adding the tel: prefix, and finally turning the resulting string into a URL.

Swift 4, iOS 11

// set up the dial sequence
let nzoneNum = "1234"
let prefix = "#5"
let dialSequence = "\(prefix)\(nzoneNum)"

// "percent encode" the dial sequence with the URL Host allowed character set
guard let encodedDialSequence =
    dialSequence.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) else {
    print("Unable to encode the dial sequence.")
    return
}

// add the `tel:` url scheme to the front of the encoded string
let dialURLString = "tel:\(encodedDialSequence)"

// set up the URL with the scheme/encoded number string
guard let dialURL = URL(string: dialURLString) else {
    print("Couldn't make the dial string into an URL.")
    return
}

// dial the URL
UIApplication.shared.open(dialURL, options: [:]) { success in
    if success { print("SUCCESSFULLY OPENED DIAL URL") }
    else { print("COULDN'T OPEN DIAL URL") }
}

Objective-C, iOS 11

// set up the dial sequence
NSString *nzoneNum = @"1234";
NSString *prefix = @"#5";
NSString *dialSequence = [NSString stringWithFormat:@"%@%@", prefix, nzoneNum];

// set up the URL Host allowed character set, and "percent encode" the dial sequence
NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed];

// add the `tel` url scheme to the front of the encoded string
NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence];

// set up the URL with the scheme/encoded number string
NSURL *dialURL = [NSURL URLWithString:dialURLString];

// set up an empty dictionary for the options parameter
NSDictionary *optionsDict = [[NSDictionary alloc] init];

// dial the URL
[[UIApplication sharedApplication] openURL:dialURL
                                   options:optionsDict
                         completionHandler:^(BOOL success) {
                             if (success) { NSLog(@"SUCCESSFULLY OPENED DIAL URL"); }
                             else { NSLog(@"COULDN'T OPEN DIAL URL"); }
                         }];
leanne
  • 7,940
  • 48
  • 77
  • Your answer is interesting: please re-post it on https://stackoverflow.com/questions/13097737/phone-call-number-with-hashtag-on-ios and vote to close Mr_T question as duplicate. – Cœur Jun 18 '18 at 06:42
2

Unfortunately you can't make calls to any number including a hashtag. Apple clearly restricts those calls: iPhoneURLScheme_Reference

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.

palme
  • 2,499
  • 2
  • 21
  • 38