簡體   English   中英

升級到Phonegap 2.9.0-設備未在Android上啟動

[英]Upgraded to Phonegap 2.9.0 - deviceready not fired on Android

從Phonegap 2.5.0升級到2.9.0之后,我再也無法觸發deviceready事件。

我嘗試過的事情:

  1. 添加包含{}cordova_plugins.json文件

  2. 在計時器中查找window.device (似乎從未初始化)(建議在這里

  3. cordova.js中刪除試圖加載cordova_plugins.json的代碼,並用finishPluginLoading()替換

似乎沒有任何作用。 我正在把頭發拉過來。 請在我還剩一些時幫忙!


到目前為止,這是我的代碼,但是經過了多次迭代,因此其中包含一些無效代碼,這些代碼顯示了我嘗試過的其他途徑:

$(document).ready(function() {
    function initializePhoneGap( success, failure ) {
        var timer = window.setInterval( function () {
            if ( window.device ) {
                window.clearInterval( timer );
                success();
            }
        }, 100 );
        window.setTimeout( function () { //failsafe
            if ( !window.device ) { //phonegap failed
                window.clearInterval( timer );
                failure();
            };
        }, 10000 ); //5 seconds
    }

    console.log( 'Waiting for launch...');
    if (navigator.userAgent.match(/(iPhone|iPod|iPad|Android|BlackBerry|IEMobile)/)) {
        //$(document).on("deviceready", didFinishLaunching, false);
        document.addEventListener("deviceready", didFinishLaunching, false);
        //initializePhoneGap( function(){ console.log('Phonegap initialized'); didFinishLaunching() }, function(){ console.log('Phonegap timed out'); didFinishLaunching() } );
    } else {
        console.log('Skipping phonegap initialization');
        didFinishLaunching();
    }

    function didFinishLaunching() {
        ....

您的ondeviceready應該是第一個被調用的東西,而不是.ready內部。

它看起來應該像這樣:

<script>
    document.addEventListener("deviceready", deviceIsReady, false);

    function deviceIsReady() {
        /*This is where all of you initialization code should go. 
          With PhoneGap the deviceready should be the first thing*/
    }

</script>

只需堅持使用PhoneGap的deviceready而不是$(document).ready()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM