I'm building an app using the ionic framework (which is built on top of Cordova) and I now want to catch the deviceready event. Around the internet I've found various methods of doing this. I've tried the following three ways:
document.addEventListener('deviceready', function () {console.log('IT IS READY!');});
$ionicPlatform.ready(function () {console.log('IT IS READY!');});
window.ionic.Platform.ready(function() {console.log('IT IS READY!');});
but none of these work. I surrounded these lines with log statements, and all code before AND after it is executed, so it doesn't halt there. I'm trying this on a physical Android device (haven't tried iOS yet).
I don't get any error messages. The only possibly relevant log I get in my terminal is one referring to the keyboard which cannot be read:
I/chromium(25678): [INFO:CONSOLE(20)] "Uncaught TypeError: Cannot read property 'Keyboard' of undefined", source: file:///android_asset/www/js/app.js (20)
Does anybody know why this doesn't work and how I can solve it? All tips are welcome!
The default 'blank' Ionic template has this code in app.js
and it works perfectly.
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
Maybe you are placing your $ionicPlatform.ready(function () {});
in the wrong place.