lakshmen
lakshmen

Reputation: 29094

Opening External Links in Phonegap with iOS

I am trying to link to an external link using the anchor tag like this: Google .

In order to do that, i added this code in appDelegate.m(the code is from here: https://gist.github.com/2012253):

- (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 ];
    }
}

But i am not still be able to link to Google... Am i doing something wrong? Need some help.

Upvotes: 0

Views: 2710

Answers (2)

I have used that piece of code in MainViewController.m in cordova 1.7.0 cordova 1.9.0 and cordova 2.1.0 and it works pretty well. You just need to move that code to the correct file.

Upvotes: 0

dhaval
dhaval

Reputation: 7659

Make sure your ExternalHosts property in Cordova.plist file is properly set. ExternalHosts is an array of hosts that you are whitelisting so that it can be accessed from your application.

For google (http and https)

google.com

http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

For example, check my demo application here

Upvotes: 1

Related Questions