Friday, April 3, 2009

Launching 3rd party apps within iPhone from your apps

It is possible to launch other applications on the iPhone that are very useful to perform features beyond your application. E.g. you don't need to embed browser object within your app to show your web page to users... just invoke in-built browser using http: for the needful. Similarly mailto: for the mail, and tel: for calling etc.

Here is some sample code/info on how to launch other apps within an iPhone through your own customized app:
  • Launch the Browser
  • Google Maps
  • Launch Apple Mail
  • Dial a Phone Number
  • Launch the SMS Application
  • Launch the Browser
  • Launch the AppStore

Launch the Browser
NSURL *url = [NSURL URLWithString:@"http://www.inavdeep.com"];
[[UIApplication sharedApplication] openURL:url];

Launch Google Maps
// Create your query ...
NSString* searchQuery = @"1 Infinite Loop, Cupertino, CA 95014";

// Be careful to always URL encode things like spaces and other symbols that aren't URL friendly
searchQuery = [addressText stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];

// Now create the URL string ...
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", searchQuery];

// An the final magic ... openURL!
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlText]];

Launch Apple Mail
mailto://${EMAIL_ADDRESS}

For example, here we are opening the email application and filling the “to:” address with contact@me.com :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://contact@me.com"]];

Dial a Phone Number
tel://${PHONE_NUMBER}

Here is an example of how we would dial the number (800) 867-5309:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://8001231234"]];

Launch the SMS Application
sms:${PHONENUMBER_OR_SHORTCODE}

NOTE: Unlike other URLs, an SMS url doesn’t use the “//” syntax. If you add these it will assume it is part of the phone number which is not.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"sms:55555"]];

Launch the AppStore
http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8

Launching the AppStore URL is exactly the same as you would launch the browser. Using the link above, here is an example of how we would launch the AppStore:

NSURL *appStoreUrl = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];
Finally, it is worth noting that you can launch another app from your customized app within same iPhone!

How is Google's generative AI boosting ads for the US and UK markets?

Advancements in technology have revolutionized the advertising industry, enabling businesses to reach a broader audience and maximize their ...