Ionic Notification not getting Received while application is running

Hi Everyone,

I have configured the ngcordova’s push notification plugin, and its working , i just need to understand few things.

While the application is closed, the notification pops up in the notification bar of the mobile. While i click the notification the application is opened normally , no sign of notification in the application so in the first controller on the application opening is write the following code

$rootScope.$on(‘pushNotificationReceived’, function(event, notification) {

  switch(notification.event) {
    case 'registered':
      if (notification.regid.length > 0 ) {
        alert('registration ID = ' + notification.regid);

    case 'message':
      // this is the actual push notification. its format depends on the data model from the push server
      alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);

    case 'error':
      alert('GCM error = ' + notification.msg);

      alert('An unknown GCM event has occurred');

So for its ok, i got the notification and performed some actions, but what about if the application is already running and the notification comes, because the application is already running there is no controller loading, so how can i perform a refresh or something in the application?

The plugin has a few broadcasts built in, see here for an explanation on how to use them or the docs with some examples. This is what you can use:

$scope.$on("$cordovaLocalNotification:trigger", function(id, state, json) {
    console.log("Notification triggered");

Handle it as you wish. Doesn’t give you the actual notification but a toast could be a decent alternative.