onNotification handler cordova-fcm-plugin-with-dependecy-updated

204 Views Asked by At

I have implemented push notifications using the cordova-fcm-plugin-with-dependecy-updated package in my vue-cordova app. Now I want to do some additional handling when a push notification is received (when the app is not in foreground). This should be done using the onNotification(data) handler, but I don't know where this handler should be placed.

When I put the code in main.js (root-level) the app doesn't even start, but showing a white screen right after the splashscreen.

FCM.onNotification((data) => {
  cordova.plugins.notification.badge.increase();
  if (data.wasTapped) {
    //Notification was received on device tray and tapped by the user.
    alert(JSON.stringify(data));
  } else {
    //Notification was received in foreground. Maybe the user needs to be notified.
    alert(JSON.stringify(data));
  }
});

Where should the handler be placed in my code, or which additional imports do I need?

0

There are 0 best solutions below