1

How do I make a call to this number *199*123456789# on iOS?

I used the following code but it doesn't work.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:*199*123456789#"]];
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1645064
  • 19
  • 1
  • 2
  • Related: https://stackoverflow.com/questions/12909631/how-to-calldialing-with-char-in-ios – Cœur Jun 18 '18 at 09:18
  • Possible duplicate of [Call a GSM Service #123#](https://stackoverflow.com/questions/4346301/call-a-gsm-service-123) – Cœur Jun 18 '18 at 12:28

3 Answers3

1

Reposted and modified from my answer to the now-closed question "iOS - I want to call phone number "#51234" in Xcode useing telprompt":

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

// 1) set up the dial sequence as a String
let dialSequence = "*199*123456789#"

// 2) "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
}

// 3) add the `tel:` url scheme to the front of the encoded string
// NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work.
let dialURLString = "tel:\(encodedDialSequence)"

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

// 5) 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

// 1) set up the dial sequence as a String
NSString *dialSequence = @"*199*123456789#";

// 2) "percent encode" the dial sequence with the "URL Host Allowed" character set
NSCharacterSet *urlHostAllowed = [NSCharacterSet URLHostAllowedCharacterSet];
NSString *encodedDialSequence = [dialSequence stringByAddingPercentEncodingWithAllowedCharacters:urlHostAllowed];

// 3) add the 'tel:' url scheme to the front of the encoded string
// NOTE: the '//' part is optional: either 'tel:' or 'tel://' will work.
NSString *dialURLString = [NSString stringWithFormat:@"tel:%@", encodedDialSequence];

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

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

// 6) 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
0

Replace * with %2A and # with %23:

NSURL *tel = [NSURL URLWithString:@"tel:%2A199%2A123456789%23"];
[[UIApplication sharedApplication] openURL:tel];
Cœur
  • 37,241
  • 25
  • 195
  • 267
-1

You need to use tel:// not just tel:

Nathanial Woolls
  • 5,231
  • 24
  • 32