Phonegap - Xcode 中的 Javascript 调试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4827213/
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
Phonegap - Javascript debugging in Xcode
提问by Lukas1
I am working on a phonegap based project. I'd like to use some debug tools, to be able to debug some variables etc into XCode console, etc. Now, I've found, that in order to do this, I need to call function console.log.
我正在研究基于 phonegap 的项目。我想使用一些调试工具,以便能够将一些变量等调试到 XCode 控制台等中。现在,我发现,为了做到这一点,我需要调用函数 console.log。
The problem is, however, when running the application in simulator no debug info is displayed in XCode console... I am using phonegap version 0.9.3, what am I doing wrong?
然而,问题是,当在模拟器中运行应用程序时,XCode 控制台中没有显示调试信息......我使用的是 phonegap 版本 0.9.3,我做错了什么?
Thanks for an answer
谢谢你的回答
采纳答案by fil maj
This feature was completed very recently (two days ago), and is not included in the 0.9.3 release. You can see this ticket in the issue trackerfor more information.
此功能是最近(两天前)完成的,未包含在 0.9.3 版本中。您可以在问题跟踪器中查看此票证以获取更多信息。
To get this working, you have to pull the latest code from the PhoneGap GitHub repository. From a shell:
要使其正常工作,您必须从PhoneGap GitHub 存储库中提取最新代码。从外壳:
$ git clone git://github.com/phonegap/phonegap-iphone.git
... and then go about building up the source from scratch. You should see it then!
...然后从头开始构建源代码。那你应该看看!
Alternatively, you replace your console.log
statements with debug.log
, and that will work in 0.9.3.
或者,您将console.log
语句替换为debug.log
,这将在 0.9.3 中起作用。
回答by Francesco Frapporti
Lukas, there is a fantastic tool you can use to debug your phonegap project.
Lukas,有一个很棒的工具可以用来调试你的 phonegap 项目。
With iWebInspectoryou basically have Firebug for your Phonegap Application. You can even live-change the code.
使用iWebInspector,您的 Phonegap 应用程序基本上拥有 Firebug。您甚至可以实时更改代码。
回答by elMarquis
Paste the following somewhere near the start of your document so that it gets executed before any of your other JavaScript.
将以下内容粘贴到文档开头附近的某个位置,以便它在任何其他 JavaScript 之前执行。
<script type="text/javascript">
window.onerror = function(message, url, lineNumber) {
console.log("Error: "+message+" in "+url+" at line "+lineNumber);
}
</script>
And enjoy viewing details of your Javascript errors in the Xcode console window.
并享受在 Xcode 控制台窗口中查看 Javascript 错误的详细信息。
UPDATE: The above technique will log errors such as undefined variables. But syntax errors such as missing commas will still cause the entire script to break without logging anything.
更新:上述技术将记录诸如未定义变量之类的错误。但是缺少逗号等语法错误仍会导致整个脚本中断而不记录任何内容。
Therefore you should add the following to the start of your onDeviceReadyfunction:
因此,您应该将以下内容添加到onDeviceReady函数的开头:
console.log('Javascript OK');
If you don't see "JavaScript OK" appearing in your log window when the app launches, then it means you have a syntax error somewhere.
如果您在应用程序启动时没有在日志窗口中看到“JavaScript OK”出现,则意味着您在某处存在语法错误。
To save hunting for missing commas, the easiest thing is to paste your code into a Javascript validator such as this one:
为了避免寻找丢失的逗号,最简单的方法是将您的代码粘贴到 Javascript 验证器中,例如:
http://www.javascriptlint.com/online_lint.php
http://www.javascriptlint.com/online_lint.php
and let it find the error for you.
让它为你找出错误。
Hopefully that takes some of the pain out of debugging.
希望这可以减轻调试的痛苦。