PushPlugin callback not called

I am using PushPlugin to handle push notifications. I am able to get device token and receive the notifications but the callback function is not being called. Here’s my service code:

'use strict';
angular.module('ntf.services')
 .factory('Notification', function (Device) {

var pushNotification;  

var tokenHandler = function(result){
   Device.updatePushToken(result);
};

var errorHandler = function(err){
  alert('error = ' + err);
};

var onNotification = function(event){
console.log("ON NOTIFICATION: " + JSON.stringify(event))
if ( event.alert )
{
    navigator.notification.alert(event.alert);
}

if ( event.sound )
{
    ...
}
 //badge update is handled here...

};
return {
   init: function(){
   pushNotification = window.plugins.pushNotification;
   if (!Device.isPushTokenSet()){
     pushNotification.register(
      tokenHandler,
      errorHandler,
      {
        "badge": "true",
        "sound": "true",
        "alert": "true",
        "ecb": "onNotification"
      }
      );
   }
 }, //init

};//return
});

The ‘onNotification’ above never gets called. What am I missing here?

Thanks

Hello,

What platform ?

Did you try to send push with app in background ? ( with logs at the same time )

This worked for me !

rdb thanks for the reply but it still does not work for me. I see the logs by PushPlugin.m and AppDelegate.m but my service callback is not being called. I’ve tried both foreground and background.

Try to :

name your ecb ‘window.onNotification’ and rename your function like this :

window.onNotification = function(event) {

My code is like this but in a controller.

That works; thanks a lot for your help