I'm migrating an iOS app form UIWebView to WKWebView. So far so good... In the previous app I disabled long press and implemented a custom long press (to do custom handling of links), however I can't get this working in the WKWebView
I've tried the following:
- (void)webView:(WKWebView *)wkWebView didFinishNavigation:(WKNavigation *)navigation {
[wkWebView evaluateJavaScript:@"document.body.style.webkitTouchCallout='none';" completionHandler:nil];
}
I've checked and that line gets executed, the response of the call is @"None"
But it responds with: Warning: Attempt to present on whose view is not in the window hierarchy!
Any ideas? SOLUTION: Inject javascript into wkwebview now works!
[self.wkWebView evaluateJavaScript:@"document.body.style.webkitTouchCallout='none';" completionHandler:nil];
This is the solution in Swift 3.0:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';")
}