Ionic Push "onNotification" only triggered when opening the app


#1

Given this piece of code:

var push = new Ionic.Push({
  "debug": true,
  "onNotification": function(notification) {
    var payload = notification.payload;
    console.log(notification, payload);
  },
  "onRegister": function(data) {
    console.log(data.token);
  }
});

As the title suggests, I was testing the function onNotification for a new push message received. The idea was to do something, like increasing the number in the icon badge (cordova-plugin-badge), but then I noticed this function was only triggered when opening the app after clicking on the new received push message (when it is on the foreground).

I guess this is the way to go, but I am just writing to know if there is a different possibility to handle this when the app is on the background.

Thank you very much in advance.


#2

You must use background mode plugin:


#3

Can you please explain how to use Background plugin in such case ??