Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable WKActionSheet on WKWebView

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];
like image 419
Daniel Åkesson Avatar asked Oct 20 '14 07:10

Daniel Åkesson


2 Answers

This is the solution in Swift 3.0:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
     webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';")
}
like image 56
Sam Avatar answered Sep 23 '22 03:09

Sam


myWkWebView.allowsLinkPreview = false
like image 27
Eric Mentele Avatar answered Sep 24 '22 03:09

Eric Mentele