Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a FCM token expire?

When do FCM tokens expire? Is it at 6 months?

like image 811
Sachin Gururaj Acharya Avatar asked Feb 01 '17 14:02

Sachin Gururaj Acharya


People also ask

Does the FCM token expire?

It doesn't expire though. It renews itself if one of the following happens. According to https://firebase.google.com/docs/cloud-messaging/android/client: -The app deletes Instance ID.

Do FCM tokens change?

Similarly to how GCM works, the FCM token can change due to token-rotation. Note: the token rotation is a rare-event. Don't expect to see it often. But still, if you care about the token you should implement onTokenRefresh() to be informed of changes.

What is the length of FCM token?

Usually, cookies are limited to 4096 bytes, which consist of name, value, expiry date etc.

How does FCM token work?

An FCM Token, or much commonly known as a registrationToken like in google-cloud-messaging. As described in the GCM FCM docs: An ID issued by the GCM connection servers to the client app that allows it to receive messages. Note that registration tokens must be kept secret.


1 Answers

It doesn't expire though. It renews itself if one of the following happens.

According to https://firebase.google.com/docs/cloud-messaging/android/client:

  1. -The app deletes Instance ID
  2. -The app is restored on a new device
  3. -The user uninstalls/reinstall the app
  4. -The user clears app data.

Monitor token generation

The onTokenRefreshcallback fires whenever a new token is generated, so calling getToken in its context ensures that you are accessing a current, available registration token. Make sure you have added the service to your manifest, then call getToken in the context of onTokenRefresh, and log the value as shown:

@Override public void onTokenRefresh() {     // Get updated InstanceID token.     String refreshedToken = FirebaseInstanceId.getInstance().getToken();     Log.d(TAG, "Refreshed token: " + refreshedToken);      // If you want to send messages to this application instance or     // manage this apps subscriptions on the server side, send the     // Instance ID token to your app server.     sendRegistrationToServer(refreshedToken); } 

EDIT

onTokenRefresh() is now deprecated. onNewToken() should be used instead.

like image 60
user2967888 Avatar answered Sep 21 '22 21:09

user2967888