title: How to handle app URLs in a UIWebView?
body: <p>I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as <a href="http://www.oceanobservations.com/thefeed/" rel="noreferrer">this one</a> and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown."</p>
  
  <p>After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in <code>-webView:shouldStartLoadWithRequest:navigationType:</code>, but realized that there might be other kinds of app links that the system can handle. So I came up with this, instead:</p>
  
  <pre><code>- (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error {
      // Give iOS a chance to open it.
      NSURL *url = [NSURL URLWithString:[error.userInfo objectForKey:@"NSErrorFailingURLStringKey"]];
      if ([error.domain isEqual:@"WebKitErrorDomain"]
          &amp;&amp; error.code == 101
          &amp;&amp; [[UIApplication sharedApplication]canOpenURL:url])
      {
          [[UIApplication sharedApplication]openURL:url];
          return;
      }
  
      // Normal error handling…
  }
  </code></pre>
  
  <p>I have two questions about this:</p>
  
  <ol>
  <li>Is this sane? I'm specifically checking for the error domain and error code and fetching the URL string from the userInfo. Is that stuff likely to remain?</li>
  <li>This does work for the above-linked app store link, but when I switch back to my app, there appears to have been a subsequent failed request that failed with "Frame load interrupted". how can I get rid of that? It doesn't happen when I have the OS handle the request from <code>-webView:shouldStartLoadWithRequest:navigationType:</code>, so it's a bit annoying.</li>
  </ol>
  
  <p>How do <em>you</em> handle such requests?</p>