Launch another app

An iOS app can launch certain other apps on the same device. The method is called a "scheme", not to be confused with the schemes in Xcode.

Briefly, you do this,

 NSString* url= @"http://www.apple.com";
 NSURL *theUrl = [NSURL URLWithString:url];
 [[UIApplication sharedApplication] openURL:theUrl];
     

"url" is a string with the content you want. theUrl is a special form derived from the readable URL but parsed into a form iOS can use. openURL is a method the application uses to handle the request.

A URL beginning with http:// is interpreted as a call to launch the browser, Safari. However, if it then requests maps.google.com, the Maps application will be launched instead of Safari. Similarly with youtube.com.

A request for a map might look like this,

 NSString* url;
 url= @"http://maps.google.com/maps?ll=";
 url = [url stringByAppendingFormat:@"%1.3f",38.0]; //latitude
 url = [url stringByAppendingString:@","];
 url = [url stringByAppendingFormat:@"%1.3f",-121.0];//longitude
 url = [url stringByAppendingString:@"&spn=0.5,0.5"];  //span of the map
 NSURL *theUrl = [NSURL URLWithString:url];
 [[UIApplication sharedApplication] openURL:theUrl];

Apple's documentation explains the various URL schemes they have implemented and how you can implement your own:

URL Scheme Reference

Advanced App Tricks in the iOS App Programming Guide

The page was last updated Wednesday, May 9, 2012 11:24 AM