[英]Upgraded to Phonegap 2.9.0 - deviceready not fired on Android
After upgrading from Phonegap 2.5.0 to 2.9.0 I can no longer get the deviceready event to fire. 从Phonegap 2.5.0升级到2.9.0之后,我再也无法触发deviceready事件。
Things I have tried: 我尝试过的事情:
Adding the cordova_plugins.json
file containing {}
添加包含
{}
的cordova_plugins.json
文件
Looking for window.device
in a timer (never seems to be initialized) (suggested here ) 在计时器中查找
window.device
(似乎从未初始化)(建议在这里 )
Removing the code from cordova.js
that atrempts loading of cordova_plugins.json
and replacing with finishPluginLoading()
从
cordova.js
中删除试图加载cordova_plugins.json
的代码,并用finishPluginLoading()
替换
Nothing seems to be working. 似乎没有任何作用。 I am pulling my hair out over this one.
我正在把头发拉过来。 Please help while I still have some left!
请在我还剩一些时帮忙!
Here is my code so far, however it has been through numerous iterations, so it contains some dead code showing other avenues I have tried: 到目前为止,这是我的代码,但是经过了多次迭代,因此其中包含一些无效代码,这些代码显示了我尝试过的其他途径:
$(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() {
....
Your ondeviceready should be the very first thing called, not inside of a .ready. 您的ondeviceready应该是第一个被调用的东西,而不是.ready内部。
It should look something like this: 它看起来应该像这样:
<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>
Just stick with PhoneGap's deviceready instead of $(document).ready() 只需坚持使用PhoneGap的deviceready而不是$(document).ready()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.