0

从 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() {
        ....
4

1 回答 1

4

你的 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()

于 2013-09-06T04:19:33.107 回答