Skip to content

Instantly share code, notes, and snippets.

@jfricker
Created July 1, 2009 23:31
Show Gist options
  • Select an option

  • Save jfricker/139149 to your computer and use it in GitHub Desktop.

Select an option

Save jfricker/139149 to your computer and use it in GitHub Desktop.
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
{
NSURL *loadURL = [ [ request URL ] retain ]; // retain the loadURL for use
if (([[loadURL scheme] isEqualToString: @"http"] ||
[[loadURL scheme] isEqualToString: @"https"] ) &&
(navigationType == UIWebViewNavigationTypeLinkClicked)) // Check if the scheme is http/https. You can also use these for custom links to open parts of your application.
return ![[UIApplication sharedApplication] openURL:[loadURL autorelease]]; // Auto release the loadurl because we wont get to release later. then return the opposite of openURL, so if safari cant open the url, open it in the UIWebView.
[loadURL release];
return YES; // URL is not http/https and should open in UIWebView
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment