Open links in Safari from WKWebView versus webView in iOS10+

502 Views Asked by At

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.

1

There are 1 best solutions below

0
On

ForWKWebView you should use navigationDelegate. About shouldStartLoadWithRequest you can write:

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