#pragma mark - WKNavigationDelegate iOS8
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
// 类似 UIWebView 的 -webView: shouldStartLoadWithRequest: navigationType:
NSString *url = [navigationAction.request.URL.absoluteString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
decisionHandler(WKNavigationActionPolicyAllow);
if ([url isContainSubString:@"tel:"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
}
}
或者
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
在这个方法中在 navigationType == UIWebViewNavigationTypeLinkClicked时
通过 [[request URL ]absoluteString]获取url的str 然后
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:xxxx"]]]