简体   繁体   中英

Open links in Safari from WKWebView versus webView in iOS10+

I've found many useful posts on the subject on how openURL is now deprecated in iOS10+. But it took me a while to get it implemented correctly in my project.

This was NOT working for me (using WKWebView), but this is how I had it in my existing code :

- (BOOL)WKWebView:(UIWebView *)WKWebView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        ...code to handle open url...
}

But, this DID work for me (using webView):

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        ...code to handle open url...
}

Why is this? My app's target deployment is 8.0 if that matters and I still have code to support the older "openURL" method.

Also, according to documentation, I should be using WKWebView .

For WKWebView you should use navigationDelegate . About shouldStartLoadWithRequest you can write:

- (void)webView:(WKWebView *)webView 
decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction 
decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM