I can't understand why the cheers solution is not working. The only thing I can provide is my working solution. There may be some layoffs or unnecessary things, because I myself tried 35 versions before I earned:
The first thing I attach to pg events in the Application Initializer and register my notification services:
Ember.Application.initializer({ name: 'phonegap', /* ...... */ initialize: function(container, application){ // Push container.register('notification:manager', GambifyApp.NotificationManager, { singleton: true }); container.register('notification:handler', GambifyApp.NotificationHandler, { instantiate: false }); container.injection('notification:handler', 'appController', 'controller:application'); container.injection('notification:handler', 'commentRoute', 'route:usergroup.comment'); } }
Then my manager service registers the device:
GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({ init: function(){ //var self = this; var pushNotification = Ember.get(window, 'plugins.pushNotification'); if(!Ember.isEmpty(pushNotification)){ if ( device.platform == 'android' || device.platform == 'Android' ) { pushNotification.register( this.successHandler, this.errorHandler, { "senderID":GambifyApp.config.android_sender_id, "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM" }); } } else { Ember.Logger.error('pushNotification Plugin not running'); } GambifyApp.NotificationHandler.manager = this; }, successHandler: function (result) { }, errorHandler: function (error) { Ember.Logger.error('Error while registering with push:' + error); }, });
Then, if successful, the ECB is called with a device identifier that can be processed by my handler:
GambifyApp.NotificationHandler = window.GambifyApp.NotificationHandler = { manager: null, onNotificationGCM: function(e){ console.log('---------- GCM Event:-----------'); console.log(e); if(e.event === "registered") { console.log(e.regid);
Hope this helps.
source share