移动App 的 ios11 和 iPhoneX 适配

原文链接:https://blog.csdn.net/lovelyelfpop/article/details/79460700

 

WKWebView 调用拨打电话功能

 

  • 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);
}
 

posted on 2018-11-26 23:21  zhangzongshan  阅读(486)  评论(0编辑  收藏  举报

导航