2012-03-13 121 views
3

这是我有的所有代码,我既没有得到Xcode日志也没有得到deviceReady事件(我没有得到任何其他平台上。在Ubuntu + Android + Eclipse上,我确实得到了控制台日志,但是没有deviceReady,也没有在chrome中)没有设备准备好,没有console.log与Xcode使用科尔多瓦1.5

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> 

Screenshot form xcode

+0

被科尔多瓦默认模板应用为你工作?? – dhaval 2012-03-14 12:24:48

+1

最近的归档不包括任何用于ios的默认模板 – Alex 2012-03-16 08:34:34

+1

当您使用Cordova模板创建项目时,它有一个示例页面的设置当您第一次运行该项目时,它会创建一个/ www文件夹,该文件夹应该可以正常工作 – dhaval 2012-03-16 10:32:30

回答

4
  1. CONSOLE.LOG只有deviceReady事件之后的作品

  2. 的PhoneGap使用不同phonegap.js文件Android和iOS,只有 android一个分发与可下载的档案。阅读 Dhaval的评论,了解如何获得ios版本。

  3. 我用Weinre调试,几乎错过了,它覆盖的console.log方法, 因此的console.log不weinre工作

+0

他们会重写console.log吗?有时候会打印,有时它不会,非常烦人。无法调试任何... – trainoasis 2014-06-24 13:51:50

0

亚历克斯指出,执行console.log不可用,直到PhoneGap设备准备就绪。通过调用它太快,你触发了一个参考错误。

删除所有现有的JavaScript,并尝试这个,而不是(用自己的自定义代码的倒数第二行替换警报):前

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")); 
} 
0

我知道有人问9个月但我偶然发现了同样的问题。

如果你想调试消息出现在你要拨打weinre控制台:

window.cordova.logger.useConsole(false); 

deviceready后。

更新:

看来,你需要运气获得控制台消息到weinre - 这就是坏:(

相关问题