Search code examples
push-notificationfirebase-cloud-messagingapple-push-notificationsandroid-notifications

Best practices on how often to get a device's FCM token


My app gets the FCM token every time the authentication wrapper decides that the user is signed in. This means that every time a user signs in, the device gets the device token to store in Firestore. However, it also means that every time the app is launched after being closed, a token is also retrieved. Is that a bad practice? If so, what is the ideal time that my app should get a device's token to ensure that the version saved on the server is still valid?


Solution

  • Get token every time you open app seems kind of excessive. I think it will be enough to handle these cases to make sure that you have the actual token on Server:

    1. Listen onNewToken() method in your FirebaseMessagingService
    2. Check token when the user logs in.
    3. Check token when the user use a new device (there may be a situation when user has 2 different tokens on 2 different devices)