I am new to ionic. I would like to reload an app when a user clicks on push notification. By reload, I mean reload all views as if someone has just started the app.
I have following working code to receive push notifications:
.run(function($ionicPlatform, $rootScope, $state, $cordovaPush, $ionicHistory,cUpdatesService, updateService) {
$ionicPlatform.ready(function() {
var config = {
"senderID": "99513553XXXX",
};
$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.transitionTo($state.current, $state.$current.params, { reload: true, inherit: true, notify: true });
//$state.reload();
location.reload();
//$state.transitionTo( $state.current, {reload : Math.random()}, { reload: true, inherit: true, notify: true } );
$state.go('tabs.cUpdates');
//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;
}
});
})