Cordova Mac如何在Safari中打开链接

3
我正在使用以下 https://github.com/apache/incubator-cordova-mac 来制作 Mac OS X 应用程序,但似乎无法打开 _blank 链接。如果有人知道如何解决这个问题,那就太好了。
答案 1)- 没有起作用
我将这个放在 WebViewDelegate.m 中 -

UIWebViewNavigationType < 是错误

- (BOOL) webView:(WebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    //return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
    }
}
2个回答

2

我认为_blank的更改是最近的,iOS尚未实现。我目前在AppDelegate.m中使用此原生代码在Safari中打开外部URL。

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    //return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
        [[UIApplication sharedApplication] openURL:url];
        return NO;
    }
    else {
        return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
    }
}

嗯,我是在 Cordova 应用程序中使用它,而不是在 Cordova Mac 组件中使用。您可能需要调整代码以在组件而不是应用程序中使用。只需查找等效的方法即可。 - codemonkey

0

这个在2.3.0上运行成功 oO'

- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType{
//return [self.viewController webView:theWebView shouldStartLoadWithRequest:request navigationType: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"] || [[url scheme] isEqualToString:@"itms-apps"]) {
    [[UIApplication sharedApplication] openURL:url];
    return NO;
}
else {
    return [ super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType ];
}}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接