0

I am building an ionic cordova app, The app is making use of Ionic Push notifications, The problem i am facing is that i want to run the code inside "onNotification" which is present in the app.js file before the execution of the controller.js .

Currently whenever i receive a notification on ColdStart,after i click on the notification, the app opens , the controller runs and then the onNotification method is called. I need a way such that the controller code is run only the onNotification code is run.

I register and listen for notifications in the app.js

.run(function($ionicPlatform,$rootScope, localStorageService, $state, $ionicLoading, $document) {

Ionic.io();
var push = new Ionic.Push({
"debug": false,


"onNotification": function(notification) {

console.log(notification.app.closed);

if(notification.app.closed){
    console.log('Notification event');
  }  
},

"onRegister": function(data) {
    console.log(data.token);
 }
});
Akil
  • 719
  • 13
  • 23
  • Add some variable so that it can differentiate app is opened from notification or not. If its opened from notification then you can ignore `onNotification` part. – Hardik Vaghani Jun 22 '16 at 04:38
  • I do have the variable, but that updates only after the controller starts running. – Akil Jun 22 '16 at 05:01

0 Answers0