我试图检索设备注册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":"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);
}
});
我也尝试了不使用window对象等的情况。我的成功处理程序始终被触发,但从未触发过ECB。
最佳答案
通过将ecb
指定为window.GambifyApp.NotificationHandler.onNotificationGCM
可以解决此问题:
pushNotification.register(
this.successHandler,
this.errorHandler, {
"senderID":GambifyApp.config.android_sender_id,
"ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
}
);
关于 Cordova Pushplugin : ecb not called,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26630558/