Launching iPhone Apps With Custom URL Scheme – Part 1

Sun, Oct 26

In an earlier post I talked about how to launch the browser from within an iPhone application using the UIApplication:openURL: method.

It is also possible to use this same technique to launch other applications on the iPhone that are very useful.

Examples of some of the key applications that you can launch via URL are:

  • Launch the Browser (see earlier post )
  • Launch Google Maps
  • Launch Apple Mail
  • Dial a Phone Number
  • Launch the SMS Application
  • Launch the Browser
  • Launch the AppStore

Launch Google Maps

The URL string for launching Google Maps with a particular keyword follows this structure:

http://maps.google.com/maps?q=${QUERY_STRING}

The only trick to this is to ensure that the value for the ${QUERY_STRING} is properly URL encoded. Here is a quick example of how you would launch Google Maps for a specific address:

1
2
3
4
5
6
7
8
9
10
11
// 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

Also very useful, is the ability to enable a user to quickly send an email by launching the email client in compose mode and the address already filled out. The format of this URI should be familiar to anyone that has done any work with HTML and looks like this:

mailto://${EMAIL_ADDRESS}

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

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"mailto://info@iphonedevelopertips.com"]];
Dial a Phone Number (iPhone Only)

You can use openURL: to dial a phone number. One advantage this has over other URLs that launch applications, is that the dialer will return control back to the application when the user hits the “End Call” button.

Anyone familiar with J2ME or WML will find this URL scheme familiar:

tel://${PHONE_NUMBER}

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

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

NOTE When providing an international number you will need to include the country code.

Launch the SMS Application

Also not supported by the iPod Touch, is the ability to quickly setup the SMS client so that your users can quickly send a text message. It is also possible to provide the body of the text message.

The format looks like this:

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.

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

NOTE: According to the official SMS specification, you should be able to send a body as well as the phone number by including “?body=” parameter on the end of the URL … unfortunately Apple doesn’t seem to support this standard.

Launching the AppStore

Finally, it is worth noting that you can launch the AppStore and have the "buy" page of a specific application appear. To do this, there is no special URL scheme. All you need to do is open up iTunes to the application you want to launch; right-click on the application icon at the top left of the page; and select Copy iTunes Store URL .

The URL will look something like this:

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:

1
2
NSURL *appStoreUrl = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8"];
[[UIApplication sharedApplication] openURL:appStoreUrl];

74 comments

URL schemes are great, but one important piece of information that you didn’t mention is that openURL: returns a boolean that can be used to determine whether the device is able to handle the URL.

For example if you do tel: or sms: on an iPod touch it will return NO and you can display an error message.

This becomes critical when you use URL schemes for applications you can download from the AppStore. My app, for example, allows you to add bookmarks to Delicious, but obviously the ‘yummy:’ URL scheme won’t work if it’s not installed!

by Stephen Darlington on Dec 3, 2008. #

What about launching some other 3rd party application. Or starting some other process from one process?

by Raj on Dec 4, 2008. #

@Stephen that is a great point. Thanks for the comment.

@Raj it is possible to invoke a 3rd party application ONLY if said application has taken the necessary steps to register the URL scheme with the phone. I’ll try to dig up an example to illustrate how this is done.

The URL scheme is the text before the “://” in the URL so if you wanted to create a scheme “foo” a URL would look like “foo://….”. You should even be able to pass parameters in the URL. I’ve not tried to do this yet, but as soon as I find out how I’ll post back here.

– Rodney

by Rodney on Dec 4, 2008. #

@Stephen:
Is that correct? It may be true for tel: and sms: URL schemes, but I don’t think it applies to custom URL schemes.

In my testing openUrl: always returns YES, even when called with an unsupported URL scheme. I can’t find a way to prevent the OS from displaying its own “Unsupported URL” alert message, nor a way to query for supported URL schemes.

by Darren on Dec 11, 2008. #

Darren, yes it does work even for custom URL schemes. The iPhone sometimes gets confused if you install and remove applications with URL schemes:

http://openradar.appspot.com/6045562

Maybe that’s what you’re seeing?

And no, there’s no (documented) way of discovering whether a URL scheme is supported. The way I do it try it and if it fails then disable the option next time. It’s imperfect but as far as I know the best you can do at the moment.

by Stephen Darlington on Dec 12, 2008. #

Does anyone know how to launch a custom application from an email or sms?

Cheers

by David Heacock on Feb 3, 2009. #

@David Heacock

The process of launching an application is as simple as including a URL in the email or sms message. Follow the steps in this article to register your application to respond to a particular URL and then just put that URL in your message.

NOTE: There is currently no push support so the user will still need to click the URL for it to actually open the application.

by Rodney Aiglstorfer on Feb 3, 2009. #

@David Heacock

I forgot which article this was … the article you need that explains how to register your own application URL is located here:

http://iphonedevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html

Cheers,
Rodney

by Rodney Aiglstorfer on Feb 3, 2009. #

Anyway to launch the iPod app to start playing a certain song?

by Dho on Feb 3, 2009. #

@Dho

To my knowledge this is not possible today.

by Rodney on Feb 3, 2009. #

I’ve seen that Apple’s own iPhone apps can send an email from a special mailer view that comes and goes, within the app– similar to how we are allowed to pick and even add/edit Contacts from within our apps.

Does anyone know if this “SendMail” API has been made available to us in the SDK?

by Scenario on Feb 16, 2009. #

@Scenario: nope, the “SendMail” API is not available unless you’re Apple. The only option is to use the mailto: URL scheme. Or include your own SMTP client.

Also, I found that I now see what @Darren is getting. This certainly worked in iPhone OS 2.0. Looks like something broke.

by Stephen Darlington on Feb 17, 2009. #

Thanks guys, now how do you launch iphone’s built-in address book?

Generally code samples talk about creating own interface into the address database (e.g. using AddressBookUI), but say you want your app to just launch iphone’s “Contacts” app? Thx. Gabe.

by gabe on Feb 21, 2009. #

@Gabe … I am not aware of a way to launch the Address book external to an App. Let us know if you find anything.

by Rodney Aiglstorfer on Feb 22, 2009. #

Hi,
I have an app in which I need to play a video. Can you tell me if there is a way I can do it without using YouTube? Does QT player support being invoked using URL? Also, once the video is completed, I would like my application to be restored? Is it possible?

Appreciate any pointers on this.

Thanks.

by Pranathi on Apr 14, 2009. #

Hi,
I want to open the calendar application from my custom application. What URL i can use for that.?

by anil on Apr 16, 2009. #

Hi
i am trying openURL for mailto functionality but no success (in simulator) using 2.2.1. can any body tell where is problem
Also i want to enter date from my app into iphone calender, any body have any idea?

Thanks

by kanayl on May 7, 2009. #

@kanayl

The simulator does not come loaded with the email application that is why you can’t use the mailto functionality in the simulator.

As for the calendar, there is not currently a way to do this.

by Rodney Aiglstorfer on May 7, 2009. #

I am trying openurl for call option, Once the call ended it returns back to my application (restarting the application). Can anyone help me , i want to return back to the same place where i clicked to call.

Thanks

by Raji on May 27, 2009. #

Hi Raji, I’m afraid that it can’t be done with the publicly available APIs.

by Stephen Darlington on May 28, 2009. #

Thanks Stephen.

by Raji on May 29, 2009. #

Hi,

I’m want to open an app if it’s also installed on the device, and notify the user otherwise, but the app hangs on the openurl line of code, so never beeps? Any ideas how I can work around this anyone?

BOOL win = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

if( win == 0 ) { void NSBeep(); };

by rob on May 29, 2009. #

Rob,

NSBeep isn’t available as part of the iPhone’s API.

Cheers,
–> Stephen

by Stephen Darlington on Jun 4, 2009. #

Thats great info thanks.
Just one beginners question. How do you go back to your app once you open the google maps.

Thanks

by Bruce on Jun 23, 2009. #

@Bruce: Raji asked the same question. The answer has not changed since then (i.e., you can’t).

Some other information has changed. In 3.0 it is now possible to detect which URL schemes are available and there is also the mail sheet API that Scenario was looking for.

by Stephen Darlington on Jun 23, 2009. #

Hi
i am trying to dial phone no from app but there is no effect against phone no. i am using
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”tel://8004664411″]];

where is the problem? thanks in advance.

by Kanyal on Jul 2, 2009. #

Hi,
Is there any way (documented or not…) to open Mail.app *not* with the default Inbox view loaded rather than the compose view?
Thanks

by John on Aug 17, 2009. #

What if I just want to query which other apps are installed on the iPhone? I know when the newest update Apple can recommend apps based on current installations. Is there any way to do this with public API? Thanks in advance.

by Game Soldier on Sep 11, 2009. #

Hi,
Is it possible to launch the Camera application like this?
Thanks

by Steven Denenberg on Sep 11, 2009. #

Steven,

You can take photos directly with the iPhone SDK without launching the Camera application, which allows you to stay within the application you are running. Or is there something specific within the camera application you are interested in?

John

by John Muchow on Sep 11, 2009. #

Hi, John,
Thanks for responding. Actually, I have already programmed the camera in to the app, but I’m thinking of taking it out, because when the camera launches and a photo is taken, it adds 16.5 Meg to the “Real Memory” used by the app (according to Instruments) and I occasionally get a memory warning. I don’t want the app to crash when Apple reviews it! Instead, I might have the user launch his Camera app, take the pictures, then return to my app to select them from his camera roll and attach them to an email within my app. That takes much less memory.

There was a posting on Apple’s developer forum about using malloc to grab the memory you need for the camera, and not launch Camera if the memory is unavailable. Sounds intruiging, but it also sounds like adding too many complications. Do you have trouble with using Camera in apps because of memory considerations?

/Steve

by Steve Denenberg on Sep 11, 2009. #

Hello!

Can I also open the SMS Application without specifing a number or anything? Just simply quit my app and start the SMS-App.
I want the user to stay in a conversation, if it is the case, select the contact(s) to send the text to within the SMS-Application itself. So could I do it like this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”sms:”]];

I read somewhere that you may be banned from the AppStore, if you use “sms:” in your application. Is this true?

by Stefan on Sep 12, 2009. #

Hi Steve,

Interesting question on the memory front and the camera. I didn’t experience any memory problems in using the camera in my applications, however, could have to do with what else is loaded in the application at the same time (or not loaded for that matter)

Are there other areas in your application where you tinker with how memory is managed. For example, in one application I was pushing the limits on memory and was able to save significant memory by not caching images as I wrote about here:

http://iphonedevelopertips.com/memory-management/images-and-caching.html

Let me know what you discover if you look into how memory used in your app.

John

by John Muchow on Sep 12, 2009. #

Hi Guys,

Can you us this process to open the “Calendar” app, the “iPhones Voicemail” page & the “mail accounts” screen?

Thank you very much.

by Max on Oct 7, 2009. #

Dialing a number in os 3.1 form our app has one issue .
Dialer doesn’t return control back to the application when the user hits the “End Call” button. Any one who can fixed this issue.

by Zorture on Oct 9, 2009. #

Hi guys,

I want to know whether it is possible to launch the SMS application via OpenUrl Scheme with the preloaded message in 3.1.

by Subha on Oct 10, 2009. #

Hi Gurus
i am working on iphone live tv app. i have a streaming link that will stream video and audio. but i don’t know how to launch video player in iPhone native app. any body have some idea or any help, how i can that. thanks in advance

by kanyal on Nov 24, 2009. #

I tried to open the app store like you suggested:

NSURL *appStoreUrl = [NSURL URLWithString:@”http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=291586600&mt=8″];

[[UIApplication sharedApplication] openURL:appStoreUrl];

But I get an error from Safari saying “Safari can’t open page because too many redirects occurred”.
Any idea why?

by roei on Jan 4, 2010. #

roei: the simulator will not open URL’s to the iTunes store, however the code will work on device.

by John Muchow on Jan 4, 2010. #

Seen a few related / unanswered queries above… Does anyone know if there is a URL Scheme Reference for the iPhone iPod app? We’d like our site to redirect content to a (pref Apple) media app that handles M3U and PLS files from HTML anchor tag. Several blogs say M3U is supported on iPhone v3.x but I’m not seeing how that happens.

by Steve Raschke on Jan 21, 2010. #

Will this approach work with ADHOC distributions or only distributions through the app store?

Jack

by Jack Hodges on Feb 3, 2010. #

Hi,
I am trying to open another application present on appstore from my iphone application,by using ur above given code but safari showing an alert “LOTS OF REDIRECTION,NOT ABLE TO OPEN”

Tell me onething is it possible that from our application we are able to delete or uninstall other application present in our iphone.

by monika on Feb 5, 2010. #

It sounds like you may be trying this on the simulator?? If so, try the application on a device and see if you have the same problem.

by John Muchow on Feb 5, 2010. #

I have the two applications (MyApp1 that will launch MyApp2), and MyApp2, both installed and running on the device using ADHOC profiles. The code event cycle is working, because if I change from @”myapp2://” to @”http://foo” (in MyApp1) and select the item while running a Safari web page to foo is launched. But returning to @”myapp2://” does nothing. I wish that I could trace the behavior and find out what is going on. It seems clear that there is no knowledge of the url scheme for myapp2 available to MyApp1. In fact, I am not sure how MyApp1 would know about any url schemes. It seems like they have to be registered outside of the device to work and that is why I asked about the ADDHOC vs. APP STORE installation.

Jack

by Jack Hodges on Feb 5, 2010. #

I am having the same issue ( defining a URL scheme with ADHOC distribution does not work ). Did you find a solution for this problem? Thanks.

by Ozzy on Jan 8, 2011. #

Is there a way to send a predefined message instantly to another phone?

Maybe send a predifined sms or something simular?

by Lars Persson on Feb 17, 2010. #

How can I launch an iPhone application from another iPhone application.

by Kumar Sharma on Apr 28, 2010. #

Kumar, here is some information from Apple that may help: Communicating with Other Apps

by John Muchow on Apr 28, 2010. #

Thank you very much. I used your code for sending my application. But I got troubled. When I am sending sms, I am not redirecting to my application, in stead of that I was put in sms application of iphone. So please help me redirecting to my application after sending sms.

by hardik on May 22, 2010. #

When an app places a call using the iPhone4 dialler, can anyone suggest a way to return to the app AS SOON as the call has connected (not ended)?

Thanks, Peter

by Bluepeters on Sep 21, 2010. #

Can any one tell me how to open “Apple Store” app from iPhone app!!
Thanks, GRD.

by grd on Dec 8, 2010. #

Were you able to open the “Apple Store” app? Also, do you know how to go to a particular product?

by R.MO on Jul 21, 2011. #

Hi Rodney,

i’m from Brazil, and don’t speak English, but I read this article and like to ask you if it’s possible open the phone app and play some keyboard tones, like those who need to be tapped to acces voice mail.

by Icaro on Dec 21, 2010. #

Great article and comments! Is there any way to launch the mail.app that first opens the inbox (not the email composer)?

by Jon on May 6, 2011. #

Hello,
This is a great article. I have one question, is it possible to launch the other app in background?
In other words, from my app, I click a button and it launches an other app but is running in the background so my application remains on top.
Thanks
lenbins

by lenbins on Jun 9, 2011. #

The current iOS only supports launching in the foreground

by John Muchow on Jun 10, 2011. #

Thank you.

by lenbins on Jun 10, 2011. #

hi
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”tel://*100#”]];
doesn’t work
that it is possible to make

by alexey on Jun 23, 2011. #

Is it possible to launch an app that you have (not in App Store)?

Thanks.

by Nicolas on Jun 26, 2011. #

If you are referring to launching an app on your device that was not downloaded from the app store? Sure, if the app is loaded and has a custom URL scheme defined, you can load/launch the app.

by John Muchow on Jun 27, 2011. #

Ok, Thanks, Im Using GameSalad, Now I cant create the Custom URL :(

You know if there is a way to Use Open Url to send some information to my site, without leaving the App?
Thanks!

by Nicolas on Jun 27, 2011. #

Hi there, will this work to launch an app using a “Web Clip” on the Home Page of an iPad?

What I want to do is put an app icon on my users’ iPad that launches a PDF file that is located at a certain spot in a WebDAV folder (no authentication required) on the internet directly in an App that has a custom URL scheme defined…

In Safari you can “Add To Home Page” and add a link onto the Home Page, so the idea would be to have an ibooks:// link rather than an http:// and it would open the pdf being linked to there within iBooks

by John on Aug 15, 2011. #

Read that “One advantage this has over other URLs that launch applications, is that the dialer will return control back to the application when the user hits the “End Call” button.”

IS this true ? I am not able to achieve this :(

by Tannyz on Aug 24, 2011. #

Thanks for the great code and discussion

by John on Oct 29, 2011. #

I actually hvae the opposite question for google maps. Is there anyway to force google maps to stay in a browser on an ipad. I have ios5 and want links in my website to stay in the safari browser and not open the ipad app. This worked fine on ios4 but on ios5 everything goes to the app. Any thoughts?

by Paul Gross on Nov 9, 2011. #

How can i return to my original app? I don’t know. help me.
URL Scheme works fine but how can i return to my main app?
help me

by ashok on Nov 24, 2011. #

Ashok, the only way I know of to return to your app would be if your app has a URL scheme that can be called from the other app.

by John Muchow on Nov 24, 2011. #

Can I use my code to ask the system to open a file, thus launching another app to handle the file open?
So I could open a PDF from my App and what ever PDF viewer is installed on the iphone/IPAD would load opening it.

Thanks…

by henry on Dec 4, 2011. #

If I open Email app using URL scheme, how can I return to my app after sending an email through Email app?

by Sahiti on Jan 2, 2012. #

FYI, here’s Apple’s documentation for these built-in URL schemes:
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/

And here is Apple documentation on implementing your own custom URL scheme:
http://developer.apple.com/library/ios/DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html#//apple_ref/doc/uid/TP40007072-CH7-SW50

by Basil Bourque on Aug 18, 2012. #

Can you launch an application from an application that is running in the background?

For example you can a background app collecting gps data, when it reaches a certain location you either send the app to the foreground or open another application automatically, is this possible?

Thanks!

by Brad on Oct 23, 2012. #

Interesting question, I haven’t tried that.

by John Muchow on Oct 23, 2012. #

how to Launch Clock App.??

by jigar on Dec 14, 2012. #

The better way maybe is use bellow code:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@”itms-apps://itunes.com/apps/appname”]];

and directly appstore app will open on your idevice.

by Arash on Jan 20, 2013. #