In the example app cordova provides through cordova create ...
, the following code listens to the deviceready
event:
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
This is nice, but what happens when the event is fired before I've had time to listen for it? As an example, replace the code from the example app (above) with the following:
bindEvents: function() {
setTimeout(function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
}, 2000)
},
In this example, this.onDeviceReady is never called. Would there not be a better, more reliable way to check if cordova is ready? Something like this:
bindEvents: function() {
setTimeout(function () {
if (window.cordovaIsReady) {
this.onDeviceReady()
} else {
document.addEventListener('deviceready', this.onDeviceReady, false);
}
}, 2000)
},