我正在尝试检索设备注册ID,以便从我的后端向其发送通知。
我已经尝试了几次:
GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({
init: function(){
var pushNotification = window.plugins.pushNotification;
window.GambifyApp.NotificationHandler = GambifyApp.NotificationHandler;
if ( device.platform == 'android' || device.platform == 'Android' )
{
console.log('pushNotification Register');
pushNotification.register(
this.successHandler,
this.errorHandler, {
"senderID":GambifyApp.config.android_sender_id,
"ecb":"window.externalOnNotificationGCM"
});
},
});
window.externalOnNotificationGCM = function (e) {
console.log('reg id:' + e.regid);
};

方法是在另一个对象内部(一切都保持不变,除了ECB:
"ecb":"window.GambifyApp.NotificationHandler.onHandler"
这是我放置处理程序的地方:
GambifyApp.NotificationHandler = window.GambifyApp.NotificationHandler = {
onHandler: function(e){
console.log('onHandler:');
if(e.event == "registered") {
console.log('reg id:' + e.regid);
}
console.log(e);
}
}
我的最后一个方法
"ecb":"GambifyApp.NotificationManager.onNotificationGCM"
这里增加了经理类:
GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({
/* ...... */
onNotificationGCM: function(e){
console.log('MESSAGE received:');
console.log(e);
}
});
我也试过没有窗口对象等。我的sucess处理程序总是被触发但从来没有ECB。
答案 0 :(得分:1)
通过将ecb
指定为window.GambifyApp.NotificationHandler.onNotificationGCM
:
pushNotification.register(
this.successHandler,
this.errorHandler, {
"senderID":GambifyApp.config.android_sender_id,
"ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
}
);