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.
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
(
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With