phonegap: open external page and then go back to app

前端 未结 3 906
遥遥无期
遥遥无期 2021-02-09 11:25

ok, browsing the questions I\'ve found the right way to load an external page into the phonegap view (i.e. without loosing the session or opening the device browser) as explaine

3条回答
  •  情深已故
    2021-02-09 12:20

    What you need is this charmer in your MainViewController.m It works for me in cordova 1.7.0 cordova 1.9.0 and cordova 2.1.0

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

提交回复
热议问题