Posts

Post not yet marked as solved
2 Replies
1.9k Views
0 I am implementing wkwebview in my tableview cell. In each cellForRow At indexPath function, wkwebview is initialized and I load an HTML string in the webview.here is my html string "<html><header><meta name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'></header><body style="font-family: 'HelveticaNeue'; font-size: 14px; color: black"><ul><li>Online application on <a href='https://twitter.com/' class='link'>https://twitter.com/</a> </li><li>Lorem Ipsum is simply dummy text of the printing and typesetting </li><li><span data-mce-mark="1">Lorem Ipsum is simply dummy text of the printing and typesetting .</span></li></ul></body> </html>"Here I calculate the dynamic height of wkwebview and it working correctlyfunc webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) { if webView.tag < self.contentHeights.count{ // todo add function let currentContentHeight = webView.scrollView.contentSize.height if (self.contentHeights[webView.tag] < 50.0 && self.contentHeights[webView.tag] < currentContentHeight) { self.contentHeights[webView.tag] = webView.scrollView.contentSize.height webView.frame = CGRect(x: webView.frame.origin.x, y: webView.frame.origin.y, width: webView.frame.width, height: currentContentHeight) self.uiViewController?.reloadTableViewrow(atIndexPath: webView.tag) } } } }But string loaded in wkwebview has hyperlinks in it, but on clicking on those hyperlinks,Decide Policy for navigation function is not calledpublic func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) { if navigationAction.navigationType == .linkActivated { let url = navigationAction.request.url if url?.description.lowercased().range(of: "http://") != nil || url?.description.lowercased().range(of: "https://") != nil || url?.description.lowercased().range(of: "//") != nil || navigationAction.targetFrame == nil{ decisionHandler(.cancel) UIApplication.shared.open(url!) } else { decisionHandler(.allow) } } else { decisionHandler(.allow) } }Any reason why this is function is not getting called?I checked if the delegate is attached or not but this function gets called the first time wkweview is initialised
Posted Last updated
.