Reload a view on receiving a push notification


#1

I would like to reload a view when a push notification is received. This view gets latest information from a server. I am using following code. I get the notification alert but view is not refreshed. Please help.

.run(function($ionicPlatform, $rootScope, $state, $cordovaPush, $ionicHistory) { $ionicPlatform.ready(function() { var config = { "senderID": "9951355xxxxx", };
$ionicPlatform.registerBackButtonAction(function (event) {
                event.preventDefault();
        }, 100);
        
$cordovaPush.register(config).then(function(result) {
  //alert(result);
}, function(err) {
  alert(err + ". Contact App developer.");
})      

});

$rootScope.$on(’$cordovaPush:notificationReceived’, function(event, notification) {
switch(notification.event) {
case ‘registered’:
if (notification.regid.length > 0 ) {
//alert('registration ID = ’ + notification.regid);
window.localStorage.setItem(“adeviceid”, notification.regid);
}
break;

  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);
      
      //$state.go($state.current, {}, {reload: true});
      //$state.go('tabs.cUpdates');
      $ionicHistory.clearCache();
      $state.go('tabs.cUpdates', {}, {reload: true});
      alert('message == ' + notification.message);
      break;
     
  case 'error':
      alert('GCM error = ' + notification.msg);
      break;     
     
  default:
    alert('An unknown GCM event has occurred. Contact App developer.');
    break;
}

});
})