Firebase Instance Id: Deprecation Of Getid() In 21.0.0
With the recent release of FirebaseInstanceId and FirebaseCloudMessaging (21.0.0) Firebase has deprecated iid package and both getToken() and getId() methods are now deprecated. Ac
Solution 1:
FirebaseInstanceId class is deprecated, to get token use FirebaseMessagingClass. The token can be generated using the following code:
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(newOnCompleteListener<String>() {
@OverridepublicvoidonComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration tokenString token = task.getResult();
// Log and toastString msg = getString(R.string.msg_token_fmt, token);
Log.d(TAG, msg);
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
});
Regarding the Firebase InstanceId, this is what the official document says:
public Task getInstanceId () -> This method is deprecated. For an instance identifier, use FirebaseInstallations.getId() instead. For an FCM registration token, use FirebaseMessaging.getToken() instead.
Solution 2:
Fcm Token
Before deprecation
valfcmToken= FirebaseInstanceId.getInstance().getToken()
Replacement
valfcmToken= FirebaseMessaging.getInstance().getToken()
FirebaseInstanceId#getId
Before deprecation
valistanceId= FirebaseInstanceId.getInstance().getId()
Replacement
Checking out the code of FirebaseInstanceId#getId()
I saw the suggestion that you should use FirebaseInstallations#getId
instead.
This method is deprecated
Use
FirebaseInstallations.getId()
instead.
valinstanceId= FirebaseInstallation.getInstance().getId()
Solution 3:
FCM Token:
Use firebase_messaging package
String? token = await FirebaseMessaging.instance.getToken();
Installation ID:
Use flutterfire_installations package
String id = await FirebaseInstallations.instance.getId();
Installation auth token:
String token = await FirebaseInstallations.instance.getToken();
Solution 4:
try this one
publicStringgetToken() {
String token;
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(newOnCompleteListener<String>() {
@OverridepublicvoidonComplete(@NonNull Task<String> task) {
if (task.isSuccessful()) {
token = task.getResult();
}
}
});
return token;
}
Post a Comment for "Firebase Instance Id: Deprecation Of Getid() In 21.0.0"