search

Home  >  Q&A  >  body text

ios - WKWebview 点击电话 href=“tel:xxx”没有效果是为什么?

WKWebview 点击电话 href=“tel:xxx”没有效果是为什么?

大家讲道理大家讲道理2771 days ago1690

reply all(7)I'll reply

  • 高洛峰

    高洛峰2017-04-17 18:01:54

    When you click the call button, you need to return
    decisionHandler(WKNavigationActionPolicyAllow) in this
    -(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandlerproxy method );
    Then in the proxy method - (void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation )navigation
    Judge [webView.URL absoluteString]

    Paste the code:

    //If you do not implement this proxy method, urls such as phone calls will be blocked by default
    -(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    decisionHandler(WKNavigationActionPolicyAllow);

    }

    • (void)webView:(WKWebView )webView didStartProvisionalNavigation:(WKNavigation )navigation
      {

      NSString *path=[YKBDateHelper convertNull:[webView.URL absoluteString]];
      NSString * newPath = [path lowercaseString];

      if ([newPath hasPrefix:@"sms:"] || [newPath hasPrefix:@"tel:"]) {

      UIApplication * app = [UIApplication sharedApplication];
      if ([app canOpenURL:[NSURL URLWithString:newPath]]) {
          [app openURL:[NSURL URLWithString:newPath]];
      }
      return;

      }
      }

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 18:01:54

    tel://xxx?

    reply
    0
  • ringa_lee

    ringa_lee2017-04-17 18:01:54

    Excuse me, has this problem been solved? I also encountered the same problem

    reply
    0
  • PHPz

    PHPz2017-04-17 18:01:54

    Is it because of the Chinese colon used?
    Similar to <a href="tel:xxx">xxx</a>, there will be no problem.

    reply
    0
  • 黄舟

    黄舟2017-04-17 18:01:54

    Try this

    <a href="tel: + 1 + 电话号码>电话号码</a>

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 18:01:54

    Colon: Chinese is used:)

    reply
    0
  • PHPz

    PHPz2017-04-17 18:01:54

    -(void)webView:(WKWebView )webView decidePolicyForNavigationAction:(WKNavigationAction )navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler

    In this method, print the value of navigationAction.navigationType. If it is 0, special treatment is required

    reply
    0
  • Cancelreply