Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase token refresh

Firebase documentation clearly states that FirebaseInstanceIdService should be implemented to access refreshed token and that manual registration is not required anymore, since the library cares for all the process.

Problem is that onTokenRefresh is only called once, and if something goes wrong in the process of transferring it to my server, application has to wait until next refresh or do a complete uninstall/reinstall.

Could I apply the same logic as previous GCM implementations? That is, on every start of my application I access token using FirebaseInstanceId.getInstance().getToken() and sent it to my server, not caring if it has already been sent. Same thing is done in onTokenRefresh.

Does this approach have any pitfall?

like image 671
Alessandro Avatar asked Jun 15 '16 06:06

Alessandro


2 Answers

Also, it seems you can call this function from outside of the service

FirebaseInstanceId.getInstance().getToken();

like image 144
Keith Holliday Avatar answered Oct 16 '22 19:10

Keith Holliday


What I suggest that at first time when you get TOKEN stored it locally (may be in shared pref) and

make one flag initialize it as a false

and then try to send TOKEN to your server it sent successfully turn flag ti true, and no need to send again.

like image 31
Gaurav Avatar answered Oct 16 '22 21:10

Gaurav