h5的拨打电话代码是
<a href="tel:13112345678">移动WEB页面JS一键拨打号码咨询功能</a>
UIWebView加载的h5,可以调用;但是WKWebView就是不行,找了半天,最后解决,在WKWebView的WKNavigationDelegate代理方法处理,代码如下:
// 处理拨打电话以及Url跳转等等
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSURL *URL = navigationAction.request.URL;
NSString *scheme = [URL scheme];
if ([scheme isEqualToString:@"tel"]) {
NSString *resourceSpecifier = [URL resourceSpecifier];
NSString *callPhone = [NSString stringWithFormat:@"telprompt://%@", resourceSpecifier];
/// 防止iOS 10及其之后,拨打电话系统弹出框延迟出现
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];
});
}
//这个地方要选择不去加载新页面 这样在当前页面就可以正常弹出电话框
decisionHandler(WKNavigationActionPolicyCancel);
}
网友评论