Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Messaging: best practice

Tags:

I'm migrating to Firebase Cloud Messaging, and I have one doubt. My application must show the login screen when launching, and if the user performs login in another account, I must stop send notifications for the older user.

  • What's the best way to do that?
  • Can I force the application to renew the token?
  • Or should I update the token's owner in my base by my own?
like image 882
Marcos Miguez Avatar asked Oct 25 '16 19:10

Marcos Miguez


People also ask

When should I use Firebase Cloud Messaging?

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4000 bytes to a client app.

Is Firebase Cloud Messaging reliable?

Reliability & Platform SupportIn 2022, Firebase Cloud Messaging and the Firebase Notification Composer experienced many major issues, with an average resolution time of 13 days. For almost 25% of the year, Firebase was having at least one major issue. Cloud Messaging issues history for 2022, YTD as of September 2022.

Can Firebase be used for messaging?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

What are the two types of messages in Firebase Cloud Messaging?

Using Firebase Cloud Messaging, we can send three types of messages, i.e., Notification Message, Data Message, and the message with both Notification & Data Payload.


1 Answers

Inside application You should renew Instance ID token and forget about the old one if You don't want to get notifications being sent to the old token. On every logout and login just take new Instance ID and update Your external database (in case Your application logic need it) with information about new token being assigned to that user :) There are no limits for generating new tokens and You cannot reuse once dropped tokens.

Renewing token is just calling getToken() again.

This is the best approach because InstanceID is in fact assigned to the "application instance" so in case of app reinstall on device or removing cache by user You'll have to get new token anyway.

like image 128
Rudolf Ratusiński Avatar answered Sep 26 '22 17:09

Rudolf Ratusiński