WKWebView加载的H5,拨打电话功能

  • (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及其之后,拨打电话系统弹出框延迟出现----ios11系统不用线程直接打电话也可以

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        dispatch_async(dispatch_get_main_queue(), ^{
            //注意主线程调用
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:callPhone]];

        });
    });

    decisionHandler(WKNavigationActionPolicyCancel);
}else{
    decisionHandler(WKNavigationActionPolicyAllow);
}

}

你可能感兴趣的:(WKWebView加载的H5,拨打电话功能)