Background
I installed PushPlugin. According to the docs I used automatic installation. But when I run
cordova run android, JavaScript returns the error, 'Cannot read property pushNotification of undefined'If I add
<script type="text/javascript" charset="utf-8" src="PushNotification.js"></script>then the error changes to the one in this question's title.
This is how my HTML loads the scripts
<script type="text/javascript" src="cordova.js"></script> <script src="js/libs/jquery-1.10.2.js"></script> <script src="js/libs/handlebars-1.1.2.js"></script> <script src="js/libs/ember-1.5.1.js"></script> <script type="text/javascript" src="js/index.js"></script> <script type="text/javascript" src="js/model.js"></script> <script type="text/javascript" src="js/router.js"></script> <script type="text/javascript" src="js/controller.js"></script> <script type="text/javascript" src="js/view.js"></script>Initialization code is in
index.jswhere afterdevicereadyI callpushNotification.register.After the
registercompletes, I callMyEmberApp.deferReadiness()After automatically installing the plugin, I just have to run
register, according to the docs. But this still leads to 'Cannot readpushNotification....'It seems that
PushNotification.jsis automatically inserted afterdevicereadyfires. But the plugin is not doing so. If I insert the script inindex.html, the errorObject has no method 'exec'occurs becausedevicereadyhasn't fired yet.devicereadyif ('device is android') { document.addEventListener("deviceready", this.onDeviceReady(), false); }
Question
What am I doing wrong? How should I do this?
Update
I just realized that I have only tried the automatic installation. I have not tried the manual steps. But that is no reason why the direct plugin install shouldn't work
                        
I finally realized that the error was due to the
EventListenerfordeviceready. I changedto
and everything fell right into place. Though this is a careless mistake, I still leave this question and it's answers for others who might encounter this issue