How to redirect when press on push massage in angular-app compiled in cordova

362 Views Asked by At

I'm using this plugin here:

https://github.com/phonegap-build/PushPlugin

Where is the behavior that gives me an option to redirect to a certain view in my angular app?

For the sake of example, in ios device it's configured as follows:

window.onNotificationAPN = function (event) {
            if (event.alert) {
                window.plugins.pushNotification.alert(event.alert);
            }

            if (event.sound) {
                var snd = new Media(event.sound);
                snd.play();
            }

            if (event.badge) {
                window.plugins.pushNotification.setApplicationIconBadgeNumber(
                    function (result) {
                        console.log('Success - ' + result);
                    },
                    function (error) {
                        console.log('Error - ' + error);
                    },
                    event.badge);
            }
        };

Im guessing somewhere in here suppose to be a code that says:

if you pressed the push, and now your here, redirect to somewhere you like.... is it possible?

1

There are 1 best solutions below

1
On BEST ANSWER

You can use $location.path() to switch / change the current route in angular. That should be possible on notification too, as long as you have access to the $location service in the push callback. You could register it in angular.module(...).run():

angular.module(...).run(function($location) {
  window.onNotificationAPN = function (event) {
    $location.path('/push-message-received');  
  };
});