capacitor push-notifications OR firebase messaging service worker

936 views Asked by At

I am confused as to which packages should I implement in my Angular 14 Ionic 6 Capacitor 4 app, for sending and receiving notifications between app users. I need to be able to handle incoming messages:

  • When app is in background - display a tappable notification (pushing to the notifications tray is not enough!) that will bring the app to foreground and further route based on received data payload.
  • When app is in foreground - process logic based on data payload received.

My initial approach was to implement with @capacitor/push-notifications, with the two listeners implemented:

pushNotificationReceived

pushNotificationActionPerformed

However, I found the following shortcomings with that approach:

  1. In background - messages are only delivered to the notifications tray - not popping up.
  2. In background, un-tapped notifications will never be processed by the app leading to important data that must mutate the application state - to be lost!
  3. In foreground, the much needed baloon popup notifications in background - are now shown (when not really needed to be shown).

Then I encountered the [firebase/messaging service worker][1] approach.

I have not yet implemented it at all, but it seems to me, that while offers the onBackgroundMessage method to capture and handle background notifications, to fall short on:

  1. Not leveraging the native notification service offered by Android/iOS
  2. Not showing any popup notification, unless I implement it myself(?)

At this point I'm somewhat confused:

  1. Is it possible that my requirements can only be met by using BOTH approaches and packages?
  2. Is it at all possible to implement both? (in which case, the same token I register upon the 'registration' listener registration in initPush(), will serve BOTH?)
  3. If one approach is enough - which is it, and how to overcome what seems to me missing, in order to fulfill my requirements?

Thank you! [1]: https://firebase.google.com/docs/cloud-messaging/js/receive

0

There are 0 answers