is there a way with ionic to bring the user to a specific page or tab when opening the app through the notification?
I send the push,my phone is in background and the user accesses the app tapping on the notification just arrived. Actually the app opens the page which is already opened, but I want it opens a destination page chosen by notification.
// ------------------------------ GCM NG-CORDOVA PUSH-----------------------------------
.run(function($ionicPlatform,ngFB,$state,$cordovaPush,$rootScope,$ionicScrollDelegate, $cordovaMedia) {
$ionicPlatform.ready(function() {
var androidConfig = {
"senderID": "XXXXXXXXXXX"
};
$cordovaPush.register(androidConfig).then(function(result) {
// Success
// alert(result);
}, function(err) {
// Error
alert(err);
});
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
//alert(notification.event);
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
// alert('registration ID = ' + notification.regid);
}
break;
case 'message':
$ionicScrollDelegate.$getByHandle('chatScroll').scrollBottom();
// this is the actual push notification. its format depends on the data model from the push server
//alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
alert(JSON.stringify(notification));
if (notification.foreground)
{
// if the notification contains a soundname, play it.
var soundfile = notification.soundname;
// if the notification contains a soundname, play it.
var media = $cordovaMedia.newMedia("/assets/www/"+ soundfile);
media.play();
alert(notification.payload.message);
}
else
{
window.location = '#/home';
//$state.go('home');
}
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
});
// WARNING: dangerous to unregister (results in loss of tokenID)
// $cordovaPush.unregister(options).then(function(result) {
// Success!
//}, function(err) {
// Error
//})
});
})
Please Help me. Where i am doing wrong?
This is my route
.config(function($ionicAppProvider,$stateProvider, $urlRouterProvider) {
$stateProvider.state('login', {
url : '/login',
templateUrl : 'templates/login.html',
controller : 'loginController'
});
$stateProvider.state('signup', {
url : '/signup',
templateUrl : 'templates/signup.html',
controller : 'signupController'
});
$stateProvider.state('home', {
url : '/home',
templateUrl : 'templates/home.html',
controller : 'homeController'
});
$stateProvider.state('profile', {
url : '/profile',
templateUrl : 'templates/profile.html',
controller : 'profileController'
});
$stateProvider.state('changePassword', {
url : '/changePassword',
templateUrl : 'templates/changePassword.html',
controller : 'changePasswordController'
});
$urlRouterProvider.otherwise("/login");
})