problem using tel: URL to initiate a call
As @bentford said one might get miscarried because the simulator does show an alert when you try to click on a phone on the contacts app, this is just an alert that gets generated because the app checks whether or not the tel:
protocol is supported on the device or not.
Adding to what he writes you might want to also add support to escape any special characters or spaces as in:
NSString *phoneStr = [NSString stringWithFormat:@"tel:%@",[self.contactDetails objectForKey:@"phone"]];
NSString *escaped = [phoneStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
Hope it helps.
Cheers.
(
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 your phone number has (
or )
in it, the Phone app will not launch.
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