Almost seven years ago when the iPhone was first released, there was a “Greg’s Head” post about iPhone telephone hyperlinks, remarking on how “tel” was used as part of a URL request to initiate a phone call from a web page in mobile safari.

The use of tel is still the most common way that a native app requests a phone call. This is done via a shared application object:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:555-555-5555"] 1 [ [ UIApplication sharedApplication ] openURL : [ NSURL URLWithString : @"tel:555-555-5555" ]

In this case, the use of tel will immediately call the number without prompting the user. When the user stops the call, Apple’s phone app remains active. In order to return to the app from which they called the number, the user needs to hit the home button and tap on the app icon. This is hardly an ideal experience for the user, and it does not encourage continued use of the app once a phone call is finished.

The pros and cons of telprompt

But, there is an alternative to tel that is much more well-behaved.

Using telprompt instead of tel in the openURL method will not only prompt the user if they wish to call the number, but after the call is finished the user will be directed back to the app instead of the Apple’s phone app.

It is hard to imagine many cases where a native app developer would prefer the use of tel over telprompt, and yet tel is more commonly used.

The primary reason for this is that Apple’s URL Scheme Reference does not mention telprompt, implying that Apple does not support the use of telprompt. While there is some concern that the use of telprompt might lead to a rejected app from the app store, there have been no reports of this occurring. A more substantial concern is that Apple might disallow the use of telprompt in a native app sometime in the future, leading to unexpected behavior in a published app.

UIWebview privately uses telprompt when sent a tel request

You can get telprompt behavior in your native app without explicitly referencing by loading a URL using tel in a UIWebView. The web view will privately execute the request using telprompt.

Worst case scenario with this solution: Apple changes the manner in which a UIWebView handles a load request with tel (i.e., having it actually use tel privately instead of telprompt).

We have implemented this in RZUtils as a component called RZTelprompt which uses a couple of class methods and a static UIWebView to make the call:

+ (void)callWithString:(NSString *)phoneString { [self callWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneString]]]; } + (void)callWithURL:(NSURL *)url { static UIWebView *webView = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ webView = [UIWebView new]; }); [webView loadRequest:[NSURLRequest requestWithURL:url]]; } 1 2 3 4 5 6 7 8 9 10 11 12 13 + ( void ) callWithString : ( NSString * ) phoneString { [ self callWithURL : [ NSURL URLWithString : [ NSString stringWithFormat : @"tel:%@" , phoneString ] ] ] ; } + ( void ) callWithURL : ( NSURL * ) url { static UIWebView * webView = nil ; static dispatch_once_t onceToken ; dispatch_once ( &onceToken, ^{ webView = [UIWebView new]; } ) ; [ webView loadRequest : [ NSURLRequest requestWithURL : url ] ] ; }

An example project

In addition to the RZTelprompt component in RZUtils, here’s a github repository with an Xcode 5.1 example project demonstrating RZTelprompt and how it compares to making phone calls via UIApplication.