Search code examples
angularjscordovaangular-ui-routercordova-pluginsphonegap-pushplugin

APN and GCM Push Notifications opening a url in cordova app


Using Cordova PushPlugin and AngularJS I want to receive a push notification and read a URL in the payload and then navigate to that page when the notification is swiped open.

How is this accomplished?

I tried this, but this is inside of a global function that is outside of angular so I wouldn't suspect the $location to work. It doesn't throw any errors though, but it also does not navigate to the url from the payload.

function onNotificationAPN(event) {
  $location.path(event.custom.url)
});

Solution

  • You can try this: Create a service "PushService" and invoke the service like below

    function onNotification(event) {
    var injector = angular.element(document.body).injector();
    injector.invoke(function (PushService) {
        PushService.onNotification(event);
    });
    

    }

    I created a tool to generate app with push notification integration with cordova and ionic. You can check it out Ionic app builder