how to open the url in safari not in webview

后端 未结 10 1719
时光说笑
时光说笑 2020-12-28 16:18

I want to open an url in safari, outisde the app and not in webview.

I implemented the UIWebViewDelegate but I am still not able to open the url. Basically I am not

相关标签:
10条回答
  • 2020-12-28 16:45

    Swift and no webview way

        if let url = NSURL(string: "http://www.apple.com") {
            UIApplication.sharedApplication().openURL(url)
        }
    
    0 讨论(0)
  • 2020-12-28 16:48

    After reading the comments I think this is what you're looking for:

    Implement this method:

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
    

    from UIWebViewDelegate and depending on that request argument you should return TRUE or FALSE. If you don't want the web view to open it, you should call:

    [[UIApplication sharedApplication] openURL:request.URL];
    

    as others mentioned and return FALSE.

    Hope this helps. Cheers!

    EDIT: If the links are not recognized in your web view, try this:

    [webView setDataDetectorTypes:UIDataDetectorTypeLink]
    
    0 讨论(0)
  • 2020-12-28 16:55

    This works for me:

    [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: @"http://www.apple.com"]];
    
    0 讨论(0)
  • 2020-12-28 16:59
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.google.com"]];
    
    0 讨论(0)
提交回复
热议问题