Disable WKActionSheet on WKWebView

谁都会走 提交于 2019-11-29 14:21:18

问题


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

回答1:


This is the solution in Swift 3.0:

func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
     webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';")
}



回答2:


I haven't verified it, but it looks like you can also use CSS to disable this functionality:

-webkit-touch-callout: none;

Source: https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-touch-callout



来源:https://stackoverflow.com/questions/26460417/disable-wkactionsheet-on-wkwebview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!