Launching the Browser from within an iPhone application

It is sometimes nice to be able to launch a browser from within your applications. Though not as elegant as the use of a UIWebView, it is much easier.

NOTE Because it is possible for an application to bind itself to a URL (like Google Maps), this technique can also be used to launch other applications on the device.

Here is a simple example of how to open safari with a specific URL:

1
2
NSURL *url = [NSURL URLWithString:@"http://www.iphonedevelopertips.com"];
[[UIApplication sharedApplication] openURL:url];

17 Comments

  1. So can we launch the app store this way to a particular product page, for example?

    Steve

  2. In theory yes, though I’m not certain that Apple has published the URL scheme for that application. I’ll look into it and post back here if I can find anything. I can see how that would be useful … in particular if you wanted to promote other apps from another app.

  3. How can I zoom UIWebView content like I am opening map on UIWebView then how can I zoom it?

  4. hi,

    can i test launching sms or calling some number using openURL in iphone simulator?

  5. @aniruddha You can’t test the SMS function that I am aware of because there is no SMS client in the emulator. You will have to test on a real device.

  6. So, it’s weird, but when I call that code, it launches the browser with two windows to the same site.

    Any thoughts?

  7. I want to program an iPhone application that would monitor in real time for the incoming text from the phone number associated with my arduino/GSM Playground. Once the text is received the next step is for the background application to simulate a button press inside the Clifford smart start application and start the vehicle. Is it possible to have this application launch the clifford smart start application and simulate a button press?

  8. this really helps me
    and it is daam easy
    thanks o(~_^)o

  9. how to config for app call to other app?
    example : [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”tel:1-408-555-5555″]];
    =>how to app working?
    just only need [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”tel:1-408-555-5555″]]; the app will be call?
    please expalin for me

  10. Say that the app is itself launched from Safari, is there a way to return to that same window/tab (with a new URL)?

  11. Regarding “newby developer” question: it appears that it is *not* possible to return to the same tab…always seems to make new one, no matter that it duplicates an existing tab’s URL…

    My question: I’ve been able to launch Safari from an action inside my running iOS application. Cool… But, I’d like to launch Safari when the user kills my app by hitting the hardware home (back?) button. If I stick the openURL call in any view controller or app delegate call that are invoked upon exit, Safari does not get launched. I presume that it is because this request comes “too late” in the process. Any suggestions?

    Thanks!

    • I would assume your statement is correct, the OS is preparing to put your app in suspended mode, therefore it ignores the request.

  12. How do you create an icon for the basic icons such as phone, photo and anything that’s not listed under schemes? I’ve tried create your own custom URL and it does not accept it.
    Thanks!

    • Hi Julie, can you provide a little more info? I’m not sure I understand just what you are hoping to do.

Comments are closed.