Launching the Browser from within an iPhone application

October 16, 2008

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

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

Steve

by Steve Wetherill on Oct 17, 2008. Reply #

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.

by Rodney Aiglstorfer on Oct 17, 2008. Reply #

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

by Devesh on Jan 23, 2009. Reply #

hi,

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

by aniruddha on Mar 10, 2009. Reply #

@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.

by Rodney Aiglstorfer on Mar 10, 2009. Reply #

@Rodney

Thanks for the comment.

by aniruddha on Mar 11, 2009. Reply #

Where do you put this and how do you call a button to launch it? Please help. Thank you!

by Sean Herman on Jul 31, 2009. Reply #

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

Any thoughts?

by Kevin Timm on Nov 12, 2009. Reply #

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?

by Jonathan Rogers on Dec 16, 2010. Reply #

Jonathan, unfortunately I don’t think what you are after is supported by any published API(s).

by John Muchow on Dec 16, 2010. Reply #

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

by nikhilesh on Sep 12, 2011. Reply #

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

by Thanh Hai on Oct 10, 2011. Reply #

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

by newby developer on Apr 26, 2012. Reply #

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!

by Frustrated Developer on Oct 1, 2012. Reply #

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

by John Muchow on Oct 1, 2012. Reply #

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!

by Julie on Apr 4, 2013. Reply #

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

by John Muchow on Apr 5, 2013. Reply #

Leave a Comment