我真的不明白,为什么你的解决方案不起作用。我唯一能提供的就是我的工作解决方案。那里可能有一些冗余或不必要的东西,因为我自己在开始工作之前尝试了 35 个版本:
第一件事是我在 App Initializer 中附加到 pg 事件并注册我的通知服务:
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');
}
}
然后我的经理服务正在注册设备:
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);
},
});
然后在成功的情况下,使用我的处理程序可以使用的设备 ID 调用 ECB:
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); // Registraion ID
}
},
};
希望这可能会有所帮助。