I've looked over the documentation, and it states that OnNewToken() will get called when a new token is generated. Typically this will be on app install, restores, or if a user clears their data. There's also times, although rare, that the token will just be invalidated and a new token will be issued.
It's the last case that I'm most curious about.
If a user is using the application, and their token becomes invalid, is OnNewToken() called then, or will it just be called the next time the application starts? In my testing I haven't been able to get OnNewToken() to be called while the application is in use. I've started the application on a fresh install, retrieved the token via OnNewToken() and then deleted the user's token separately outside of that method, and OnNewToken() is not called until I stop the application and start it again.
It's fine if that's how it works. I'm just trying to figure out if I need to account for on the fly token changes while a user is running the application.
Also, a second and slightly related question, is it bad practice to check a user's FCM token when they log in to make sure they have the latest token?
If you manager a token registry yourself, you typically check and send an updated token to the registry/server in two places:
FirebaseMessaging.Instance.GetToken(), to ensure you have the latest token for that user when the app starts.onNewToken on your service, to ensure you have the latest token for that user when the service is active.So on your second question: it is indeed quite common to call FirebaseMessaging.Instance.GetToken() in the main method or first activity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With