美文网首页
iOS WKWebView 拦截超链接

iOS WKWebView 拦截超链接

作者: ZT_Story | 来源:发表于2020-05-21 15:30 被阅读0次

    项目更换了WKWebView之后,一些webview中的超链接没办法触发,需要实现navigationDelegate协议才可以

    - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
        if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
            // 通过浏览器访问
           [[UIApplication sharedApplication] openURL:navigationAction.request.URL];
            decisionHandler(WKNavigationActionPolicyCancel);
        } else {
            decisionHandler (WKNavigationActionPolicyAllow);
        }
        return ;//不添加会崩溃
    }
    

    相关文章

      网友评论

          本文标题:iOS WKWebView 拦截超链接

          本文链接:https://www.haomeiwen.com/subject/qgozohtx.html