UIWebView 中奇怪的 WebKit 错误 - 这可以被捕获吗?
我正在将 iPad 上文档目录的子目录中的一些 HTML / JS 加载到 UIWebView 中。到目前为止一切正常。为了调试 JS - 我在 JS 文件中放置了一些 alert(..);
语句。大多数情况下,此警报没有问题,但偶尔会在控制台中引发错误并且应用程序崩溃:
WebKit在webView中丢弃了未捕获的异常:runJavaScriptAlertPanelWithMessage:initeratedByFrame:delegate:<(null) >已为类“Publication”和 HTTP 方法“ANY”注册了路由
问题 1:可能是什么问题?我的意思是......这是一个简单的alert();似乎是什么导致了控制台中的此错误。
问题 2:我可以在我的应用程序中捕获此错误吗?这样应用程序就不会因为一个简单的 JSalert() 而崩溃;
谢谢
I'm loading some HTML / JS from a subdirectory of my documents directory on iPad into a UIWebView. Everything works fine so far. For debugging the JS - Part i've put some alert(..);
statements in the JS-File. Most of the time there is no problem with this alerts, but now and then there raises an error in console and the App crashes:
WebKit discarded an uncaught exception in the webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: delegate: <(null)> A route has already been registered for class 'Publication' and HTTP method 'ANY'
Question 1: What could be the problem? I mean ... it is a simple alert(); what seems to cause this error in console.
Question 2: can i catch this errors in my app? This way the app wouldn't crash because of a simple JS alert();
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以为 UIWebView 类创建 JavaScriptAlert 类别。 JavaScriptAlert+UIWebView.h
重写方法:
这应该处理来自 JavaScript 的警报。
然后在 javascript 方面,如果您没有在调试模式下运行,则可以将警报或控制台日志设置为无操作函数。像这样的东西
You can create a JavaScriptAlert category to your UIWebView class. JavaScriptAlert+UIWebView.h
Override the method:
This should handle the alerts from JavaScript.
Then on the javascript side of things, if you are not running in debug mode, you can set the alert or console log to a no-op function. Something like