Cordova Pushplugin:ecb不叫 [英] Cordova Pushplugin: ecb not called

查看:148
本文介绍了Cordova Pushplugin:ecb不叫的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试检索设备注册ID,以便从我的后端向其发送通知。

I am trying to retrieve the device registration ID in order to send notifications to it from my backend.

我已经尝试过几次:


  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);
    };


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

  1. Approach was Inside another Object (Everything stays the same, except the 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);
    }
}


b $ b


  1. 我最后一次使用

  1. My last approach with

"ecb":"GambifyApp.NotificationManager.onNotificationGCM"


此处添加到管理器类中:

And here the additions to the manager class:

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

    onNotificationGCM: function(e){
        console.log('MESSAGE received:');
        console.log(e);
    }
});

我也试过没有窗口对象等。我的成功处理程序总是触发,但从来没有ECB。

I have also tried without the window object etc. My sucess handler is always triggered but never the 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不叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆