2017-12-17 4 views
1

iOSアプリケーションには、WebKitを使用したWebビューがあり、電話番号などの連絡先情報があります。このアプリでは、ユーザーがアンカータグをクリックできるようにして、アプリケーションがその番号に電話したいかどうかをクライアントに尋ねます。私は自分のhtmlで次のように書いています。iOSアプリケーションのWeb-view内の電話リンク

<meta name="format-detection" content="telephone=yes"> 

私は運がないすべての以下のアンカー構造も試しました。

<a href="tel:+x-xxx-xxx-xxx">+x-xxx-xxx-xxx</a> 
<a href="tel:xxx-xxx-xxx">xxx-xxx-xxx</a> 
<a href="tel:(xxx) xxx-xxx">(xxx) xxx-xxx</a> 
<a href="tel:(xxx)-xxx-xxx">(xxx)-xxx-xxx</a> 

私はあなたが何をすべきか、すべてが保留せずに、単純なクリックでクリックすると、このダイアログが表示されるためのが、Androidの中の順序でアンカータグに保持することがあります。 iOSでそれができるかどうか、どうすればいいのか教えてください。 what happen when I press and hold on the anchor tag

答えて

0

問題の解決策を見つけるために、1週間以上テストしてから問題ないです。
これが解決策です。ユーザーが(Webビュー内のアプリケーションから)クリックすると、何が起こるかを処理するために書いたコードを重要視しているので、電話の構造にはまったく問題はありませんでした。その責任クラスで
(あなたのビューコントローラ)も

extension ViewController: WKNavigationDelegate, WKUIDelegate { 
    // handle it here 
    func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { 
     // print(navigationAction.request.url!) 
     // if the URL have tel in it then use the iOS to open it not the webkit 
     if (navigationAction.request.url!.absoluteString.contains("tel")) { 
      UIApplication.shared.openURL(navigationAction.request.url!) 
      decisionHandler(.cancel) 
     } else if (!(navigationAction.request.url!.absoluteString.contains(MAINURLNOTTOGOOUTSIDE))) { 
      // if the URL is something outside of the one specified in that string "MAINURLNOTTOGOOUTSIDE", open it using the iOS not the webkit 
      UIApplication.shared.openURL(navigationAction.request.url!) 
      decisionHandler(.cancel) 
     } else { 
      decisionHandler(.allow) 
     } 
    } 

    func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { 
     let app = UIApplication.shared 
     if (navigationAction.targetFrame == nil) { 
      if (navigationAction.request.url!.scheme?.contains("tel"))! { 
       if (app.canOpenURL(navigationAction.request.url!)) { 
        app.openURL(navigationAction.request.url!) 
       } 
      } 
     } 
     return nil 
    } 
    // handle if failed to connect to the server 
    func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) { 
     var message = "" 
     var title = "" 
     var button = "" 

     if (Locale.preferredLanguages[0].contains("ar")) { 
      title = "خطأ" 
      message = "تعذر الوصول الى الخادم الرجاء المحاولة في وقت لاحق" 
      button = "حسنا" 
     } else { 
      title = "Error" 
      message = "Unable to access server Please try again later" 
      button = "OK!" 
     } 
     let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) 
     alert.addAction(UIAlertAction(title: button, style: .default, handler: nil)) 
    } 
    // handle if failed to connect to the server 
    func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) { 
     var message = "" 
     var title = "" 
     var button = "" 

     if (Locale.preferredLanguages[0].contains("ar")) { 
      title = "خطأ" 
      message = "تعذر الوصول الى الخادم الرجاء المحاولة في وقت لاحق" 
      button = "حسنا" 
     } else { 
      title = "Error" 
      message = "Unable to access server Please try again later" 
      button = "OK!" 
     } 
     let alert = UIAlertController(title: title, message: message, preferredStyle: .alert) 
     alert.addAction(UIAlertAction(title: button, style: .default, handler: nil)) 
    } 
} 

はviewDidLoadメソッドでは、次の含めることを忘れないでください

self.WebView.navigationDelegate = self 
関連する問題