0

我正在尝试使用如下锚标记链接到外部链接:Google

为了做到这一点,我在 appDelegate.m 中添加了这段代码(代码来自这里: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 ];
    }
}

但我仍然无法链接到谷歌......我做错了什么吗?需要一些帮助。

4

2 回答 2

1

确保您ExternalHosts在 Cordova.plist 文件中的属性设置正确。ExternalHosts 是您列入白名单的主机数组,以便可以从您的应用程序访问它。

对于谷歌(http 和 https)

google.com

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

例如,在这里查看我的演示应用程序

于 2012-07-04T17:27:22.017 回答
0

我在科尔多瓦 1.7.0 科尔多瓦 1.9.0 和科尔多瓦 2.1.0 的 MainViewController.m 中使用了那段代码,它工作得很好。您只需将该代码移动到正确的文件中。

于 2012-11-05T06:37:54.163 回答