Initiating Phone Calls

As was demonstrated in the last section, the openURL method calls Safari to launch web site URLs. What's actually going on is this: each protocol is associated with a specific handler application. As was the case with our last demonstration, URLs beginning with http:// and https:// are associated with Safari and cause it to be opened whenever openURL is called using those protocol prefixes. Just as openURL can be used to open web sites in Safari, it can also be used to place phone calls. This is done by using the protocol prefix of tel://:

NSURL *url = [ [ NSURL alloc ]
    initWithString: @"tel://212-555-1234" ];
[ self openURL: url ];

When the openURL method is used on a URL beginning with tel://, the phone application will be launched and the call will be automatically placed. Do try and ensure that your application doesn't have any bugs and accidentally places expensive overseas calls or prank calls to the White House.

Get iPhone Open Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.