Cordova Pushplugin:没有叫ecb

m0c*_*m0c 6 ember.js cordova phonegap-pushplugin

我正在尝试检索设备注册ID,以便从我的后端向它发送通知.

我已经尝试了几次:

  1. 在我的对象之外

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);
    };
Run Code Online (Sandbox Code Playgroud)

  1. 方法是在另一个对象内部(除ECB外,一切都保持不变:

    "ecb":"window.GambifyApp.NotificationHandler.onHandler"
    
    Run Code Online (Sandbox Code Playgroud)

这是我放置处理程序的地方:

GambifyApp.NotificationHandler =  window.GambifyApp.NotificationHandler = {
    onHandler: function(e){
        console.log('onHandler:');
        if(e.event == "registered") {
            console.log('reg id:' + e.regid);
        }
        console.log(e);
    }
}
Run Code Online (Sandbox Code Playgroud)
  1. 我的最后一个方法

    "ecb":"GambifyApp.NotificationManager.onNotificationGCM"
    
    Run Code Online (Sandbox Code Playgroud)

这里增加了经理类:

GambifyApp.NotificationManager = window.GambifyApp.NotificationManager = Ember.Object.extend({
    /* ...... */

    onNotificationGCM: function(e){
        console.log('MESSAGE received:');
        console.log(e);
    }
});
Run Code Online (Sandbox Code Playgroud)

我也试过没有窗口对象等.我的sucess处理程序总是被触发但从来没有ECB.

Ajo*_*joy 1

ecb该问题通过指定为解决window.GambifyApp.NotificationHandler.onNotificationGCM:

pushNotification.register(
    this.successHandler,
    this.errorHandler, {
        "senderID":GambifyApp.config.android_sender_id,
        "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
    }
);
Run Code Online (Sandbox Code Playgroud)