- 1.HTML 要标记添加标记电话代码
<a href="tel:13112345678">移动WEB页面JS一键拨打号码咨询功能</a>
- 2.WKWebView 调用 <WKNavigationDelegate> 代理
_webView.navigationDelegate = self;
- 3.实现代理方法
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler
代理是实现代码:
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(nonnull WKNavigationAction *)navigationAction decisionHandler:(nonnull void (^)(WKNavigationActionPolicy))decisionHandler{
NSURL *url = navigationAction.request.URL;
NSString *scheme = [url scheme];
UIApplication *app = [UIApplication sharedApplication];
WKNavigationActionPolicy actionPolicy = WKNavigationActionPolicyAllow;
if ([scheme isEqualToString:@"tel"]) {
if ([app canOpenURL:url]) {
CGFloat version = [[[UIDevice currentDevice]systemVersion]floatValue];
if (version >= 10.0) {
/// 大于等于10.0系统使用此openURL方法
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:url];
}
}
}
/* 这句话一定要实现 不然会异常 */
decisionHandler(actionPolicy);
}
网友评论