2012-03-13 84 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 - 這就是壞:(

相關問題