title: Reliably opening App Store links from a UIWebView
body: <p>I have an app that will display web pages within a UIWebView. The pages it shows may contain links to other iPhone apps on the App Store.</p>
  
  <p>In a normal browser on a desktop computer, clicking these App Store links would take me through a number of URL redirects and eventually end up opening iTunes and taking me to the page for that App.</p>
  
  <p>Is there a way to ensure that when an App Store link is clicked inside my UIWebView that the App Store app on the iPhone will open and show the app?</p>
  
  <p>What I've been seeing in my tests is that there are several types of links that can result in an App Store page, those being:</p>
  
  <ul>
  <li>phobos links - phobos.apple.com/etc etc etc</li>
  <li>itunes.com/app/appname links</li>
  <li>referral / affiliate links</li>
  <li>any that I don't know of</li>
  </ul>
  
  <p>When I open any of these links in a desktop browser they will work and eventually open iTunes.
  When I open any of these links from within the iPhone the UIWebView goes through a number of redirects and eventually one of two things will happen:</p>
  
  <ul>
  <li>The redirects don't work properly and I end up with a page did fail to load method call</li>
  <li>The redirects work and the iTunes app is opened, a search for the app name is done, and then I get a message from iTunes explaining it can't connect to the store.</li>
  </ul>
  
  <p>The only time I've been able to get the App Store app to open is by using a direct iTunes link to the app without any referral or redirects.</p>
  
  <p>Obviously for referral or affiliate links, I do not want to strip out the referral ID or affiliate ID. I shouldn't deprive them of a referral if it was their link that is clicked.</p>
  
  <p>So any help would be greatly appreciated.</p>
  
  <p>Thanks.</p>