APP中H5页面实现拨打电话功能

 <a href="tel:400-0000-000">400-0000-000</a>
 //如失效,就在head标签里加上
 <meta name="format-detection" content="telephone=yes"/>

如果浏览器上能用,但是app中
ios提示:链接失效
android提示:net::ERR_UNKNOWN_URL_SCHEME错误
就表示原生缺少以下代码,

// 处理拨打电话以及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(WKNavigationActionPolicyAllow);  
}`

你可能感兴趣的:(前端)