WKWebView 内部点击链接跳转浏览器打开
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
// WKNavigationTypeLinkActivated --> A link with an href attribute was activated by the user.
if (navigationAction.navigationType == WKNavigationTypeLinkActivated) {
if ([[UIApplication sharedApplication] canOpenURL:navigationAction.request.URL]) {
[[UIApplication sharedApplication] openURL:navigationAction.request.URL options:@{} completionHandler:nil];
}
decisionHandler(WKNavigationActionPolicyCancel);
} else {
decisionHandler (WKNavigationActionPolicyAllow);
}
return ;
}
原文地址
https://blog.csdn.net/minghuyong2016/article/details/80552988