Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem using tel: URL to initiate a call

Tags:

iphone

I'm trying to initiate a call from within an iPhone app.

This related code works and opens Safari as expected:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.apple.com"]]; 

But, when I replace the http URL with a tel URL the resulting code does not invoke the phone app:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:3035551212"]]; 

No exceptions or alerts are generated (in the simulator or on a device).

Any idea what the problem might be with my invocation?

Thanks.

like image 303
denton Avatar asked May 01 '09 17:05

denton


2 Answers

The iphone will dial a number using either of the formats listed below. But, it will do nothing if you are in the simulator. It took me 30 minutes of banging my head to figure this out.

[[UIApplication sharedApplication]                      openURL:[NSURL URLWithString:@"tel://15415551234"]];  [[UIApplication sharedApplication]                      openURL:[NSURL URLWithString:@"tel:15415551234"]];  [[UIApplication sharedApplication]                      openURL:[NSURL URLWithString:@"tel:1-541-555-1234"]]; 

Link for Apple documentation on the tel: url scheme

Link for openURL documentation

like image 145
bentford Avatar answered Sep 22 '22 22:09

bentford


(and )are actually no problem if you use stringByAddingPercentEscapesUsingEncoding as suggested by samiq. Same goes for +, / and spaces. It's a URL, so escaping seems natural.

If I'm guessing right, Apple's regular phone number recognition will be used in the tel: scheme handler, if you escape correctly.

(missing reputation to make it a comment)

like image 26
Sebastian Avatar answered Sep 22 '22 22:09

Sebastian