iOS WKWebView 拦截超链接

2020-05-21  本文已影响0人  ZT_Story

项目更换了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 ;//不添加会崩溃
}
上一篇下一篇

猜你喜欢

热点阅读