Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 3.1 open link in Safari on iOS6

I'm building a iOS app with Cordova 3.1. I have a link I would like to open in Safari. I've installed the org.apache.cordova.inappbrowser plugin and it worked well on my iPhone (iOS 7) and on the simulator (iOS5;iOS6.1;iOS7) but if I try (iOS6) on all devices it doesn't work.

Does anybody know how to fix this or tried it on a real device running iOS6? I'm using this code to open the link:

window.open('http://www.google.nl', '_system');
like image 996
Hugo Avatar asked Oct 10 '13 23:10

Hugo


1 Answers

well I've implemented this through native side (Objective C)

Add this method in 'MainViewController.m'

- (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = [request URL];
    NSString *str = url.absoluteString;
    NSRange range = [str rangeOfString:@"http://"];
    NSRange range1 = [str rangeOfString:@"https://"];

    if (range.location != NSNotFound || range1.location != NSNotFound) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
    }
}

This take cares of both 'http' and 'https' link for both iOS6 & iOS7, and opens the link in default browser of the device.

like image 197
Siddhartha Gupta Avatar answered Nov 05 '22 21:11

Siddhartha Gupta