在 WKWebView 上禁用 WKActionSheet [英] Disable WKActionSheet on WKWebView
问题描述
我正在将一个 iOS 应用从 UIWebView 迁移到 WKWebView.到目前为止一切顺利......在以前的应用程序中,我禁用了长按并实现了自定义长按(以自定义链接处理),但是我无法在 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
我尝试了以下方法:
- (void)webView:(WKWebView *)wkWebView didFinishNavigation:(WKNavigation *)navigation {
[wkWebView evaluateJavaScript:@"document.body.style.webkitTouchCallout='none';" completionHandler:nil];
}
我已经检查并执行了该行,调用的响应是@"None"
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!
有什么想法吗?解决方案:将 javascript 注入 wkwebview 现在可以工作了!
Any ideas? SOLUTION: Inject javascript into wkwebview now works!
[self.wkWebView evaluateJavaScript:@"document.body.style.webkitTouchCallout='none';" completionHandler:nil];
推荐答案
这是 Swift 3.0 中的解决方案:
This is the solution in Swift 3.0:
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
webView.evaluateJavaScript("document.body.style.webkitTouchCallout='none';")
}
这篇关于在 WKWebView 上禁用 WKActionSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!