6

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

I already gave it several tries:

  1. Outside my Object

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. Approach was Inside another Object (Everything stays the same, except the ECB :

    "ecb":"window.GambifyApp.NotificationHandler.onHandler"
    

And here is where i put the handler:

GambifyApp.NotificationHandler =  window.GambifyApp.NotificationHandler = {
    onHandler: function(e){
        console.log('onHandler:');
        if(e.event == "registered") {
            console.log('reg id:' + e.regid);
        }
        console.log(e);
    }
}
  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);
    }
});

I have also tried without the window object etc. My sucess handler is always triggered but never the ECB.

Ajoy
  • 1,838
  • 3
  • 30
  • 57
m0c
  • 2,180
  • 26
  • 45
  • Did you solve this issue? – Ajoy Nov 25 '14 at 06:04
  • 1
    Yes, i got it working with: "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM" – m0c Nov 25 '14 at 09:25
  • Could you have a look at my issue too? http://stackoverflow.com/questions/27077173/pushplugin-typeerror-object-object-has-no-method-exec – Ajoy Nov 25 '14 at 09:57
  • It's probably worth noting that the notification event, unlike the success handler, does not fire in the simulator at all. – Mirthquakes Aug 31 '15 at 00:41

1 Answers1

1

The issue was solved by specifying ecb as window.GambifyApp.NotificationHandler.onNotificationGCM:

pushNotification.register(
    this.successHandler,
    this.errorHandler, {
        "senderID":GambifyApp.config.android_sender_id,
        "ecb":"window.GambifyApp.NotificationHandler.onNotificationGCM"
    }
);
Ajoy
  • 1,838
  • 3
  • 30
  • 57