Posts

Showing posts with the label wkwebview

WKWebview problems with opening ads or links

WKWebview problems with opening ads or links I created a iOS webapp with WKWebview (Swift) for our website. Everything is going fine, but I have a lot of problems with clicking on ads and links. I handled it like this: func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if navigationAction.navigationType == .linkActivated { let url = navigationAction.request.url if let url = navigationAction.request.url, let host = url.host, !host.hasPrefix("www.example"), UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url) print(url) print("Redirected to browser. No need to open it locally") decisionHandler(.cancel) } else if url?.description.lowercased().range(of: "tel:") != nil || url?.description.lowercased().range(of...