<?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>Arash Payan &#124; Blog &#187; uiwebview</title>
	<atom:link href="http://arashpayan.com/blog/index.php/tag/uiwebview/feed/" rel="self" type="application/rss+xml" />
	<link>http://arashpayan.com/blog</link>
	<description>(Place witty tagline here)</description>
	<lastBuildDate>Sun, 23 May 2010 22:28:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Open links from UIWebView in MobileSafari</title>
		<link>http://arashpayan.com/blog/index.php/2008/09/06/open-links-from-uiwebview-in-mobilesafari/</link>
		<comments>http://arashpayan.com/blog/index.php/2008/09/06/open-links-from-uiwebview-in-mobilesafari/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 08:13:39 +0000</pubDate>
		<dc:creator>Arash</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[mobilesafari]]></category>
		<category><![CDATA[uiwebview]]></category>

		<guid isPermaLink="false">http://arashpayan.com/blog/?p=37</guid>
		<description><![CDATA[If you&#8217;ve embedded a UIWebView in your iPhone/iPod app, you may not want the user to suffer through surfing all successive pages through it. Instead, you can open up your first page inside a UIWebView and any links the user tries to follow will instead open up in MobileSafari.
All you need to do is set [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve embedded a <code>UIWebView</code> in your iPhone/iPod app, you may not want the user to suffer through surfing all successive pages through it. Instead, you can open up your first page inside a <code>UIWebView</code> and any links the user tries to follow will instead open up in MobileSafari.</p>
<p>All you need to do is set the <code>UIWebView</code>&#8217;s delegate, to an object that implements the optional method <code>webView:shouldStartLoadWithRequest:navigationType:</code> (part of the <code>UIWebViewDelegate</code> protocol). Then whenever the initial page is loaded or a link is followed in that view, the delegate&#8217;s method will be called. You&#8217;ll want to return <code>YES</code> for the page you initially load, and then return <code>NO</code> for all others, and open the URL in MobileSafari. Here&#8217;s what the method implementation should look like:</p>
<div style="text-align:left;color:#000000; background-color:#ffffff; border:solid black 1px; padding:0.5em 1em 0.5em 1em; overflow:auto;font-size:small; font-family:monospace; ">- (<span style="color:#881350;">BOOL</span>)<span style="color:#6c0540;">webView:</span>(UIWebView *)webView<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">shouldStartLoadWithRequest:</span>(<span style="color:#400080;">NSURLRequest</span> *)request<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#6c0540;">navigationType:</span>(UIWebViewNavigationType)navigationType<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">if</span><span style="color:#003369;"> </span>([[[request <span style="color:#6c0540;">URL</span>] <span style="color:#6c0540;">absoluteString</span>] <span style="color:#6c0540;">isEqual:</span><span style="color:#760f15;">@&quot;http://arashpayan.com/myInitialPage/&quot;</span>])<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">YES</span>;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;[[UIApplication <span style="color:#6c0540;">sharedApplication</span>] <span style="color:#6c0540;">openURL:</span>[request <span style="color:#6c0540;">URL</span>]];<br />
&nbsp;&nbsp;&nbsp;&nbsp;<br />
&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:#881350;">return</span> <span style="color:#881350;">NO</span>;<br />
}</div>
<p>By returning <code>NO</code> from the delegate method, we&#8217;re telling the web view not to load the link the user tapped, but instead we redirect the opening of the link to <code>[UIApplication openURL:]</code> (MobileSafari).</p>
]]></content:encoded>
			<wfw:commentRss>http://arashpayan.com/blog/index.php/2008/09/06/open-links-from-uiwebview-in-mobilesafari/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
