Open Mobile Safari from a Link in a WebView

前端 未结 5 1716
不思量自难忘°
不思量自难忘° 2020-11-30 10:00

Is there a URI scheme to open Mobile Safari to a specific URL?

e.g.,

Open Google in Safari         


        
5条回答
  •  醉梦人生
    2020-11-30 10:11

    OK, I think I understand what you are asking for.

    Have a class implement the UIWebViewDelegate protocol. Implement the method

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

    This method gets called whenever the user clicks a link in your webview. You can get the URL the user clicked on be inspecting the request parameter. You can then intercept any links you want to open in mobile Safari rather then inside your webView and then call -openURL: on the shared application as in my other answer.

    [[UIApplication sharedApplication] openURL:URLFromRequest];
    

提交回复
热议问题