【问题标题】:cordova mac open URL in safari科尔多瓦 mac 在 Safari 中打开 URL
【发布时间】:2012-06-12 08:08:43
【问题描述】:

我正在使用以下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];
    }
}

【问题讨论】:

    标签: windows cordova safari hyperlink


    【解决方案1】:

    我认为 _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 组件中使用它。您可能需要调整代码以在组件而不是应用程序中使用。只需寻找等效的方法。
    【解决方案2】:

    这个工作于 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 ];
    }}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多