我正在尝试检索设备注册ID,以便从我的后端向它发送通知. 我已经尝试了几次: 在我的对象之外 GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({ init: function(){
我已经尝试了几次:
>在我的对象之外
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); } });
我也试过没有窗口对象等.我的sucess处理程序总是被触发但从来没有ECB.
通过将ecb指定为window.GambifyApp.NotificationHandler.onNotificationGCM来解决该问题:pushNotification.register( this.successHandler, this.errorHandler, { "senderID":GambifyApp.config.android_sender_id, "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM" } );