2017-12-17 14 views
1

전화 번호를 비롯한 일부 문의 정보가있는 웹보기 (WebKit 사용)가있는 iOS 앱이 있습니다. 앱에서 사용자가 앵커 태그를 클릭 할 수있게하려면 앱에서 해당 번호로 전화를 걸 것인지 묻습니다. 나는 html에 다음과 같은 내용을 썼다.iOS 앱에서 웹보기 내부의 전화 링크

<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> 

나는 모든 것을 당신이해야 할 것은 단지 대기없이 간단한 클릭 안드로이드 표시이 대화뿐만에 순서대로 클릭하고 앵커 태그에 유지해야합니다. iOS에서 그게 가능합니까? 그렇다면 어떻게 알려주시겠습니까? what happen when I press and hold on the anchor tag

답변

0

해당 문제에 대한 해결책을 찾으려면 일주일 이상 테스트 한 후 확인하십시오.
여기 해결책이 있습니다. 사용자가 웹보기 안의 앱에서 클릭하면 발생하는 일을 처리하기 위해 작성한 코드가 중요하기 때문에 전화 구조는 중요하지 않습니다. 그 책임이있는 클래스에서
(보기 컨트롤러)도

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