I'm trying to setup push notifications inside an initializer in an Ember CLI project. My initializer includes:
initialize: function(container, application) {
var globals = container.lookup("route:application").get('globals');
application.deferReadiness();
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
var startAppJob = setTimeout(function(){application.advanceReadiness();}, 10000),
pushNotification = window.plugins.pushNotification;
if ( device.platform == 'android' || device.platform == 'Android' ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"xxx",
"ecb":"onNotificationGCM"
});
}
}
So far so good. Except the ecb now expects the "onNotificationGCM" function to be in the global scope. So, where should the following go?
onNotificationGCM = function(e) {
switch( e.event ){
case 'registered':
clearTimeout(startAppJob)
application.advanceReadiness();
if ( e.regid.length > 0 ){
globals.set('push_registration_id', e.regid)
globals.set('push_device_type', 'iandroidos')
console.log('registered')
}
break;
Declaring it with window.onNotificationGCM or this.onNotificationGCM inside the intializer doesn't work:
processMessage failed: Error: ReferenceError: onNotificationGCM is not defined
This question Cordova Pushplugin: ecb not called suggests altering the callback which in their example becomes:
"ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
Except in Ember CLI what would this be inside an intializer? Is it even possible to access or is there a better way to implement all this in Ember CLI?
Thanks in advance for any help!
Aucun commentaire:
Enregistrer un commentaire