简体   繁体   English

调试iOS上的Cordova(PhoneGap)代码

[英]Debugging Cordova (PhoneGap) code on iOS

I'm working on an app I want to host in iOS via Cordova (PhoneGap). 我正在开发一个我想通过Cordova(PhoneGap)在iOS上托管的应用程序。 I've run into some problem when I try to access the device.platform and device.version properties. 当我尝试访问device.platform和device.version属性时遇到了一些问题。 I'm not sure what the problem is. 我不确定问题是什么。 Either way, I can't figure out how to peek into the code to get a better idea of what's going on. 无论哪种方式,我都无法弄清楚如何窥探代码以更好地了解正在发生的事情。

I thought I could just fire up the .html in the desktop version of Safari, however, that didn't provide any insights. 我想我可以在桌面版Safari中启动.html,但是,它没有提供任何见解。 In short: 简而言之:

  1. How do I debug code running inside of Cordova? 如何调试Cordova内部运行的代码?
  2. Any ideas why I can't just do a "alert(device.platform);"? 任何想法为什么我不能只做一个“警报(device.platform);”?

Thank you! 谢谢!

Since iOS 6 you can just enable the Develop menu in Safari and use Safari Web Inspector to remotely debug Cordova app in either iOS Simulator or USB attached devices. 从iOS 6开始,您只需启用Safari中的“开发”菜单,并使用Safari Web Inspector在iOS模拟器或USB连接设备中远程调试Cordova应用程序。 If you've used Chrome's debugger you'll feel right at home. 如果您使用过Chrome的调试器,那么您会感到宾至如归。

  1. I use nifty debugging tool called Weinre , which is a lifesaver when debugging cordova( phonegap) apps. 我使用名为Weinre的漂亮的调试工具 ,这是调试cordova(phonegap)应用程序时的救星。 It basically is a remote debugging tool resembling usual webkit developer tools available in Chrome and some other browsers. 它基本上是一个远程调试工具,类似于Chrome和其他一些浏览器中常用的webkit开发人员工具。

  2. Make sure that Cordova is loaded before you try to call device.platform. 在尝试调用device.platform之前,请确保已加载Cordova。 Cordova is loaded when deviceready js event is triggered. 触发deviceready js事件时会加载Cordova。

as well as Weinre, there is also iWebInspector which is useful and perhaps better on ios. 除了Weinre之外,还有iWebInspector,它在ios上很有用,也许更好。 http://www.mobilexweb.com/blog/debugging-web-safari-phonegap-iphone-ipad http://www.mobilexweb.com/blog/debugging-web-safari-phonegap-iphone-ipad

I think it maybe only applies to the simulator but thats fine for most cases anyway. 我认为它可能只适用于模拟器,但对大多数情况来说这都很好。 It is more Xcode and iOs debugging solution in my opinion . 在我看来,它是更多的Xcode和iOs调试解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM