Wednesday, June 10, 2009

Launching application via URL scheme


Launching application via URL scheme


Here I will try to explain how to make your application launch another application on the system. There will be a minimal code written for these feature like everything else in Objective C and Cocoa Touch framework. Application that have support for URL’s can be launched with a call to the UIApplication’s openURL:.

Everything will work fine if the URL is well formed and the application is properly registered. We’ll do that later. iPhone OS will take care of the rest. For example:

1.- (IBAction) someButton {
2.
3.[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://inchoo.net"]];
4.
5.}

This code above will run Safari browser and our site will pop up. There is several predefined URL schemes for integrated iPhone OS applications such as Mail. If you decide that you want launch another application (for testing purpose) from your application, you must first register URL scheme of application that is going to be launched. That is easy part of job. To register a custom URL scheme, just add a this in Info.plist.

infoplist1

When we have done that, we just implement this code in method that triggers our button from nib file.

1.- (IBAction) anotherButton {
2.
3.[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myapp://"]];
4.
5.}

And now we can launch this application from our application. This is very simple and easy to implement so try it!


Copy from here