PhoneGap: Opening external URL's in Safari

后端 未结 12 892
耶瑟儿~
耶瑟儿~ 2020-11-30 03:04

I\'ve just upgraded to PhoneGap 1.6.1 and I can no longer get external URL\'s to open in Safari.

Prior to this version I had patched AppDelegate.m as follows:

<
12条回答
  •  难免孤独
    2020-11-30 03:41

    I have used this in the 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://"];
        //HACK to make url open in safari
        if (range.location != NSNotFound) {
            [[UIApplication sharedApplication] openURL:url];
            return NO;
        }
        else {
            return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
        }
    }
    

提交回复
热议问题