简体   繁体   English

从WKWebView与iOS10 +中的webView在Safari中打开链接

[英]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+. 我发现了关于该主题在iOS10 +中如何弃用openURL的许多有用文章。 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 : 这不适用于我(使用WKWebView),但这是我在现有代码中的处理方式

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

But, this DID work for me (using webView): 但是,此DID对我有用(使用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. 如果这很重要,我的应用程序的目标部署是8.0,并且我仍然具有支持较旧的“ openURL”方法的代码。

Also, according to documentation, I should be using WKWebView . 另外,根据文档, 应该使用WKWebView

For WKWebView you should use navigationDelegate . 对于WKWebView ,应使用navigationDelegate About shouldStartLoadWithRequest you can write: 关于shouldStartLoadWithRequest您可以编写:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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