iOS WKWebView 拨打电话 拦截不到

今天使用WKWebView 拦截H5 a标签打电话拦截不到

// 使用方法
// 在收到响应后,决定是否跳转
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler{

    NSLog(@"absoluteString = %@",navigationResponse.response.URL.absoluteString);
    NSString * strRequest = navigationResponse.response.URL.absoluteString;
    if ([strRequest containsString:@"tel:"]) {
        NSString * phoneNum = [strRequest substringFromIndex:[@"tel:" length]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phoneNum]] options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:nil];
        decisionHandler(WKNavigationResponsePolicyCancel);
    }else{
        decisionHandler(WKNavigationResponsePolicyAllow);
    }
}

始终都收不到响应的拦截
更改为
/* 在发送请求之前,决定是否跳转 */

- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
    NSString * strRequest = navigationAction.request.URL.absoluteString;
    if ([strRequest containsString:@"tel:"]) {
        NSString * phoneNum = [strRequest substringFromIndex:[@"tel:" length]];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phoneNum]] options:@{UIApplicationOpenURLOptionsSourceApplicationKey:@YES} completionHandler:nil];
        decisionHandler(WKNavigationActionPolicyCancel);
    }else{
        decisionHandler(WKNavigationActionPolicyAllow);
    }
}

你可能感兴趣的:(iOS WKWebView 拨打电话 拦截不到)