没有设备准备和没有console.log Xcode使用cordova1.5

这是我所有的代码,我既没有得到xcode的日志,也没有得到deviceReady事件(我也没有得到任何其他平台上。在Ubuntu + Android + Eclipse上我得到的控制台日志,但没有deviceReady 。也不在铬)

js / cordova-1.5.0.js存在并被加载,表示一个警告声明我已经放在那里。 任何线索我应该在哪里看? 提前致谢 ;)

<div id="d"></div> <script> function foo() {console.log('test'); document.getElementById('d').innerHTML += 'called';} window.setTimeout(foo, 5000); window.setTimeout(foo, 15000); window.setTimeout(foo, 25000); window.setTimeout(foo, 35000); alert('hi'); console.log('non timed console.log'); </script> <script src="js/cordova-1.5.0.js"></script> <script> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { alert('deviceReady'); //somewhy this never happens } </script> 

截图形式的Xcode

  1. Console.log仅在deviceReady事件之后起作用

  2. Phonegap为android和ios使用不同的phonegap.js文件,并且只有android版本与可下载的存档一起分发。 阅读Dhaval的评论,了解从哪里获得ios版本。

  3. 我使用Weinre进行debugging,几乎错过了它覆盖console.log方法,因此console.log不适用于weinre

正如Alex所指出的,console.log在您的PhoneGap设备准备好之后才可用。 通过调用它太快,你触发了一个参考错误。

删除所有现有的JavaScript,然后尝试使用它(用自定义代码replace倒数第二行的警报):

 var app = { // denotes whether we are within a mobile device (otherwise we're in a browser) iAmPhoneGap: false, // how long should we wait for PhoneGap to say the device is ready. howPatientAreWe: 10000, // id of the 'too_impatient' timeout timeoutID: null, // id of the 'impatience_remaining' interval reporting. impatienceProgressIntervalID: null, // Application Constructor initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // Bind any events that are required on startup. Common events are: // `load`, `deviceready`, `offline`, and `online`. bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); // after 10 seconds, if we still think we're NOT phonegap, give up. app.timeoutID = window.setTimeout(function(appReference) { if (!app.iAmPhoneGap) // jeepers, this has taken too long. // manually trigger (fudge) the receivedEvent() method. appReference.receivedEvent('too_impatient'); }, howPatientAreWe, this); // keep us updated on the console about how much longer to wait. app.impatienceProgressIntervalID = window.setInterval(function areWeThereYet() { if (typeof areWeThereYet.howLongLeft == "undefined") { areWeThereYet.howLongLeft = app.howPatientAreWe; // create a static variable } areWeThereYet.howLongLeft -= 1000; // not so much longer to wait. console.log("areWeThereYet: Will give PhoneGap another " + areWeThereYet.howLongLeft + "ms"); }, 1000); }, // deviceready Event Handler // // The scope of `this` is the event. In order to call the `receivedEvent` // function, we must explicity call `app.receivedEvent(...);` onDeviceReady: function() { app.iAmPhoneGap = true; // We have a device. app.receivedEvent('deviceready'); // clear the 'too_impatient' timeout . window.clearTimeout(app.timeoutID); }, // Update DOM on a Received Event receivedEvent: function(id) { // clear the "areWeThereYet" reporting. window.clearInterval(app.impatienceProgressIntervalID); console.log('Received Event: ' + id); myCustomJS(app.iAmPhoneGap); // run my application. } }; app.initialize(); function myCustomJS(trueIfIAmPhoneGap) { // put your custom javascript here. alert("I am "+ (trueIfIAmPhoneGap?"PhoneGap":"a Browser")); } 

我知道这个问题是在9个月之前问的,但我偶然发现了同样的问题。

如果你想debugging消息出现在weinre控制台,你必须调用:

 window.cordova.logger.useConsole(false); 

装置准备好后。

更新:

看来,你需要运气得到控制台信息weinre – 那坏:(