Phonegap iOS:InAppBrowser打开但点击链接有时无法打开页面和事件"通过"到主webView

时间:2014-03-12 00:23:25

标签: ios cordova

我正在使用phonegap和HTML5开发iOS应用。 在应用程序中的launchImage之后,我打开InAppBrowser,它会立即打开。 但是,点击其中的链接有时无法打开所需的页面,事件“落到”主webView。

即,点击链接时InAppBrowser已关闭。

请帮我解决,因为过去两天我一直坚持这样做。

2 个答案:

答案 0 :(得分:0)

试试这个

在@end标记

之前将此代码放在MainViewController.m中
- (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];
    }
}

答案 1 :(得分:0)

绕过错误代码解决了此问题。这是一个肮脏的解决方法,但无法帮助它。在“CDVInAppBrowser.m”中,修改如下,InAppBrowser成功加载我的URL。

- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error
{
    //By passing error code
    if(error.code == -999)
        return;
    // log fail message, stop spinner, update back/forward
    NSLog(@"webView:didFailLoadWithError - %i: %@", error.code, [error localizedDescription]);

    self.backButton.enabled = theWebView.canGoBack;
    self.forwardButton.enabled = theWebView.canGoForward;
    [self.spinner stopAnimating];

    self.addressLabel.text = NSLocalizedString(@"Load Error", nil);

    [self.navigationDelegate webView:theWebView didFailLoadWithError:error];
}