<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>iPhone Application Developer - iPhone Developer Labs - iPhone Application Development &#187; iPhone Custom URL schemes</title>
	<atom:link href="http://www.iphonedeveloperlabs.com/tag/iphone-custom-url-schemes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iphonedeveloperlabs.com</link>
	<description>iPhone application developer resource - application development, updates &#38; news for iphone developers</description>
	<lastBuildDate>Mon, 06 Sep 2010 11:50:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Custom URL schemes and Launching other applications &#8212; Best Practices for iPhone OS 3.0</title>
		<link>http://www.iphonedeveloperlabs.com/2009/08/24/custom-url-schemes-and-launching-other-applications-best-practices-for-iphone-os-3-0/</link>
		<comments>http://www.iphonedeveloperlabs.com/2009/08/24/custom-url-schemes-and-launching-other-applications-best-practices-for-iphone-os-3-0/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 13:40:35 +0000</pubDate>
		<dc:creator>Rama Krishna</dc:creator>
				<category><![CDATA[iPhone SDK Tips]]></category>
		<category><![CDATA[iPhone SDK Tutorials]]></category>
		<category><![CDATA[Best Practices for iPhone OS 3.0]]></category>
		<category><![CDATA[iPhone App Developers]]></category>
		<category><![CDATA[iPhone app Developers help]]></category>
		<category><![CDATA[iPhone App Development]]></category>
		<category><![CDATA[iPhone Custom URL schemes]]></category>
		<category><![CDATA[iPhone OS 3.0]]></category>
		<category><![CDATA[iPhone SDK Help]]></category>

		<guid isPermaLink="false">http://www.iphonedeveloperlabs.com/?p=84</guid>
		<description><![CDATA[Custom URL schemes and Launching other iPhone Applications -- Best Practices for iPhone OS 3.0]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.iphonedeveloperlabs.com%2F2009%2F08%2F24%2Fcustom-url-schemes-and-launching-other-applications-best-practices-for-iphone-os-3-0%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.iphonedeveloperlabs.com%2F2009%2F08%2F24%2Fcustom-url-schemes-and-launching-other-applications-best-practices-for-iphone-os-3-0%2F&amp;source=iphonedevlabs&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>How to open other applications like phone dialer, SMS, Safari, Google Maps, iTunes or <a href="http://www.iphonedeveloperlabs.com/category/appstore-iphone-application-submission-help/">AppStore</a> or any other <a href="http://www.iphonedeveloperlabs.com/tag/iphone-app-development/">iPhone applicatio</a>n?</p>
<p>&#8220;openURL&#8221; is the API to use to achieve any of the above and many more.<br />
If you need to let your application users quickly dial APPLE from within your app, just include the following line</p>
<blockquote><p>[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:8006927753"]];</p></blockquote>
<p>Similarly, you could initiate SMS application by using openURL with &#8220;sms: &#8220;, but unfortunately you cannot fill in the SMS content as Apple does not yet support it.<br />
There are many more things you could do with this API like launching Google Maps, Safari with any website like you want or even the AppStore links to your apps which you want the users to buy.</p>
<p><strong>Checking support for URLs of other applications</strong><br />
Until the release of iPhone OS 3.0 it was not possible to find if there are any applications installed on the device which handle the URL scheme you are about to use. But now it is possible through the following API</p>
<blockquote><p>- (BOOL)canOpenURL:(NSURL*)url</p></blockquote>
<p>Call the above API before using &#8220;openURL&#8221; to make sure your call will &#8220;certainly&#8221; be handled by a registered application. If you were <a href="http://www.iphonedeveloperlabs.com/tag/iphone-app-development/">developing an iphone app</a> which lets a phone call be made from within it, do the following</p>
<blockquote><p>// this will fail if the device is an iPod<br />
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:111"]])<br />
{<br />
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel:111"]];<br />
}<br />
else<br />
{<br />
// show an Alert here indicating that the call can&#8217;t be completed<br />
}</p></blockquote>
<p>Apart from using &#8220;canOpenURL&#8221;, do check the return value from &#8220;openURL&#8221; too and take appropriate action.</p>
<p>You should also use &#8220;canOpenURL&#8221; to find out if any features (like calling a number and SMS) that are not accessible on iPod should be disabled or hidden. Showing &#8220;phone&#8221; icons and letting them be clicked in your application on an iPod is a sure shot way to get your application rejected for uploading to AppStore.</p>
<p><strong>Registering and handling custom URL schemes</strong><br />
If you are developing a great tool and can be used by other applications, you can register custom URL schemes and implement them. To create custom URL schemes just add them to your application&#8217;s &#8220;info.plist&#8221; file.</p>
<blockquote>
<ul>
<li> To the root element of your application&#8217;s &#8220;info.plist&#8221; file, add a row with key named &#8220;URL types&#8221;.</li>
<li> Expand it to find &#8220;item1&#8243; in it, expand it and edit the value for key &#8220;URL identifier&#8221; to look something like &#8220;com.yourcompany.yoururlscheme&#8221;</li>
<li> Add another row to &#8220;item1&#8243; with key &#8220;URL Schemes&#8221;. Type in the first few characters of your URL scheme.<br />
For an example, if you wish to use url formats like <strong>abc://part1/part2</strong>, just enter &#8220;abc&#8221; for URL Schemes</li>
</ul>
</blockquote>
<p>Once you have created and registered your own URL formats/schemes, you can handle incoming URL requests by implementing the following UIApplicationDelegate method</p>
<blockquote><p>- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url</p></blockquote>
<p>Before parsing and/or handling the URL, make sure it is in the right format and follows all rules of your URL scheme.</p>
<p>The above method was the only place where you can handle incoming URLs until iPhone OS 3.0 arrived. For iPhone OS 3.0 and above, the <strong>preferred place to handle incoming URLs</strong> is</p>
<blockquote><p>- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions</p></blockquote>
<p>This method should return whatever &#8220;handleOpenURL&#8221; API would have returned if it were implemented. If you implement the above delegate method of UIApplication, IPhone OS will not invoke the following methods</p>
<blockquote><p>- (void)applicationDidFinishLaunching:(UIApplication*)application<br />
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)url</p></blockquote>
<h3  class="related_post_title">Related Posts</h3><ul class="related_post"><li>September 21, 2009 -- <a href="http://www.iphonedeveloperlabs.com/2009/09/21/apple-announced-app-store-resource-center-for-iphone-app-developers/" title="Apple Announced App Store Resource Center for iPhone App Developers">Apple Announced App Store Resource Center for iPhone App Developers</a> (0)</li><li>August 26, 2009 -- <a href="http://www.iphonedeveloperlabs.com/2009/08/26/memory-issues-in-iphone-os-3-0-sample-app/" title="Memory Issues in iPhone OS 3.0 : Sample Code">Memory Issues in iPhone OS 3.0 : Sample Code</a> (2)</li><li>March 30, 2010 -- <a href="http://www.iphonedeveloperlabs.com/2010/03/30/iphone-os-3-2-gm-seed-now-available-for-iphone-developers/" title="iPhone OS 3.2 GM Seed &#8211; Now Available for iPhone Developers">iPhone OS 3.2 GM Seed &#8211; Now Available for iPhone Developers</a> (0)</li><li>March 20, 2010 -- <a href="http://www.iphonedeveloperlabs.com/2010/03/20/apple-now-accepting-ipad-apps/" title="Apple Now Accepting iPad Apps">Apple Now Accepting iPad Apps</a> (4)</li><li>March 15, 2010 -- <a href="http://www.iphonedeveloperlabs.com/2010/03/15/good-news-for-app-developers-multi-tasking-added-to-os-4-0/" title="Good News for App Developers : Multi-Tasking Added to OS 4.0">Good News for App Developers : Multi-Tasking Added to OS 4.0</a> (0)</li></ul>
	Tags: <a href="http://www.iphonedeveloperlabs.com/tag/best-practices-for-iphone-os-3-0/" title="Best Practices for iPhone OS 3.0" rel="tag nofollow">Best Practices for iPhone OS 3.0</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-app-developers/" title="iPhone App Developers" rel="tag nofollow">iPhone App Developers</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-app-developers-help/" title="iPhone app Developers help" rel="tag nofollow">iPhone app Developers help</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-app-development/" title="iPhone App Development" rel="tag nofollow">iPhone App Development</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-custom-url-schemes/" title="iPhone Custom URL schemes" rel="tag nofollow">iPhone Custom URL schemes</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-os-3-0/" title="iPhone OS 3.0" rel="tag nofollow">iPhone OS 3.0</a>, <a href="http://www.iphonedeveloperlabs.com/tag/iphone-application-development-sdk-help/" title="iPhone SDK Help" rel="tag nofollow">iPhone SDK Help</a><br />
]]></content:encoded>
			<wfw:commentRss>http://www.iphonedeveloperlabs.com/2009/08/24/custom-url-schemes-and-launching-other-applications-best-practices-for-iphone-os-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
