从 Phonegap 2.5.0 升级到 2.9.0 后,我无法再触发 deviceready 事件。
我尝试过的事情:
添加
cordova_plugins.json
包含的文件{}
在计时器中寻找
window.device
(似乎从未被初始化)(在这里建议)从中删除代码
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() {
....