ryannmahajan
ryannmahajan

Reputation: 33

Will FCM show that a token that was previously used is no longer available? When?

Imagine a users installs and opens my app. A FCM Registration token is generated and sent to my server. Later, say the user clears my app's data. When he then opens the app, a new Token will be generated. So, since there's no way for me to know this yet, I send notifications as normal to the old Registration too. Now :

  1. Will FCM assume that the device is offline and keep trying to send the notification until the end of its lifetime (default 4 weeks) ?

  2. If not, how long till it returns registration-token-not-registered error?

Upvotes: 1

Views: 1174

Answers (1)

AL.
AL.

Reputation: 37778

  1. No. The FCM servers will know that the token is expired immediately.

  2. From #1, it will send it back immediately.

The thing that might get confusing here is the steps on where you'd actually receive the NotRegistered error. Here's are two possible scenarios:

  1. Device installed the app. Token is generated and sent to your server.
  2. You send a push notification to the token.
  3. FCM server checks, token is still valid, enqueues the message to be sent as soon as feasible.

Next one is from your scenario:

  1. Device installed the app. Token is generated and sent to your server.

  2. User goes offline and clears app data. Previous token is now invalid, but the InstanceID service is not yet informed of it since the device is offline.

  3. You send a push notification to the token. FCM sees that token as valid, sends you back a success response and enqueues the message to be sent as soon as feasible.

    Here, the token is currently still currently valid. So you'd receive a success response like usual.

  4. Device goes online. InstanceID service syncs, lets it know that the old token is now invalid and requests for a new one. New token gets generated.

      1. 5 Almost at the same time that the device goes online, FCM checks if the token is still valid. If not, then it will drop the enqueued messages.

The thing to always remember is that FCM is working as a middle-man. Hope this clears things up. Cheers!

Upvotes: 2

Related Questions