Skip to content

Instantly share code, notes, and snippets.

@bergantine
Forked from mwbrooks/projectAppDelegate.m
Created March 13, 2012 18:51
Show Gist options
  • Save bergantine/2030708 to your computer and use it in GitHub Desktop.
Save bergantine/2030708 to your computer and use it in GitHub Desktop.
In PhoneGap-iOS, open external links in the external browser (Safari.app). #ios #objectivec #phonegap
/**
* Note: the following function should already exist in your application delegate file.
* Replace it with the following implementation.
*
* Thanks to @purplecabbage for implementation.
*/
// ...
/**
* Start Loading Request
* This is where most of the magic happens... We take the request(s) and process the response.
* From here we can re direct links and other protocalls to different internal methods.
*/
- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
// Intercept the external http requests and forward to Safari.app
// Otherwise forward to the PhoneGap WebView
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
else {
return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment