检测 UIWebView 中的 JavaScript 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4001769/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detecting JavaScript errors in a UIWebView
提问by Alex Wayne
Possible Duplicate:
How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?
可能的重复:
我的 iPhone Objective-C 代码如何在 UIWebView 中收到 Javascript 错误的通知?
I'm running into a very annoying issue developing javascript for a UIWebView
in an iPhone application. If there is an error in the javascript, it silently fails and halts execution of the function it was running. And some errors do not happen in a desktop browser, so all appears fine. I then run it on an iPhone and get a massive failure as the function craps out half way through, and no idea why. I then slowly and methodically comment out various lines of code until no catastrophic failures happen, in order to pinpoint the offending line of code.
我UIWebView
在为 iPhone 应用程序开发 javascript 时遇到了一个非常烦人的问题。如果 javascript 中有错误,它会默默地失败并停止执行它正在运行的函数。有些错误不会在桌面浏览器中发生,所以一切看起来都很好。然后我在 iPhone 上运行它并在功能进行到一半时出现严重故障,不知道为什么。然后我慢慢地、有条不紊地注释掉各种代码行,直到没有发生灾难性的故障,以便查明有问题的代码行。
This sucks.
这很糟糕。
So is there any way at all to get a UIWebView
to log or report in anyway javascript errors? They are obviously happening, I just don't know why or how, and it's making my life hard.
那么有什么办法可以让UIWebView
无论如何记录或报告javascript错误?它们显然正在发生,我只是不知道为什么或如何发生,这让我的生活变得艰难。
采纳答案by Prcela
There is already post for same problem:
已经有关于同样问题的帖子:
How can my iPhone Objective-C code get notified of Javascript errors in a UIWebView?
我的 iPhone Objective-C 代码如何在 UIWebView 中收到 Javascript 错误的通知?
You can hook UIWebView control to hidden WebKit framework and get all exceptions, executed functions and similar.
您可以将 UIWebView 控件挂钩到隐藏的 WebKit 框架并获取所有异常、执行的函数等。
回答by Rudiger
Have you tried in the iOS Safari Settings to turn on the debug console? Just go to settings ->Safari -> Developer and turn on debug console. The UIWebView should be at the very least extremely similar as to whats in the iOS Safari App. Might get you started.
您是否尝试过在 iOS Safari 设置中打开调试控制台?只需转到设置 -> Safari -> 开发人员并打开调试控制台。UIWebView 至少应该与 iOS Safari 应用程序中的内容非常相似。可能会让你开始。
回答by hotpaw2
Are you implementing the UIWebView's didFailLoadWithError delegate?
你在实现 UIWebView 的 didFailLoadWithError 委托吗?
It might give you an error code.
它可能会给你一个错误代码。