I have the following problem :
In my main controller, I have this function that is called when a push arrived on iOS device :
onNotificationAPN = function(event) {
if (event.alert) {
navigator.notification.alert(event.alert);
}
if (event.sound) {
var snd = new Media(event.sound);
snd.play();
}
if (event.badge) {
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
// do some work with event
$state.go(‘there’);
}
But it can’t work because $state is unknown.
Have you already tried to change the angular state after a push notification?
It’s hard to tell from your sample, but I’m assuming that onNotificationAPN is a global function outside of Angular. Generally speaking, Angular doesn’t talk to the outside world. So, you have to resort to a few hacks to get that global function to talk to angular.
Here’s how I do it:
document.addEventListener('push-notification', function(event) {
var body = document.getElementsByTagName("body")[0];
var appController = angular.element(body).scope();
appController.reportNotificationReceived(event);
});