Firebase Instanceid.Instanceid().Token() Method Is Deprecated

Firebase InstanceID.instanceID().token() method is deprecated

Fetching the current registration token

Registration tokens are delivered via the method messaging:didReceiveRegistrationToken:. This method is called generally once per app start with an FCM token. When this method is called, it is the ideal time to:

  • If the registration token is new, send it to your application server.
  • Subscribe the registration token to topics. This is required only for new subscriptions or for situations where the user has re-installed the app.

You can retrieve the token directly using instanceIDWithHandler:. This callback provides an InstanceIDResult, which contains the token. A non null error is provided if the InstanceID retrieval failed in any way.

You should import FirebaseInstanceID

  import FirebaseInstanceID

objective C

on your getTokenMethod

[[FIRInstanceID instanceID] instanceIDWithHandler:^(FIRInstanceIDResult * _Nullable result,
NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error fetching remote instance ID: %@", error);
} else {
NSLog(@"Remote instance ID token: %@", result.token);
}
}];

Swift

InstanceID.instanceID().instanceID { result, error in
if let error = error {
print("Error fetching remote instange ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}

Update

InstanceID is now deprecated. Try

Messaging.messaging().token { token, error in
// Check for error. Otherwise do what you will with token here
}

Firebase instance id: deprecation of getId() in 21.0.0

FirebaseInstanceId class is deprecated, to get token use FirebaseMessagingClass. The token can be generated using the following code:

FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}

// Get new FCM registration token
String token = task.getResult();

// Log and toast
String 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.

FirebaseInstanceIdService is deprecated

firebaser here

Check the reference documentation for FirebaseInstanceIdService:

This class was deprecated.

In favour of overriding onNewToken in FirebaseMessagingService. Once that has been implemented, this service can be safely removed.

Weirdly enough the JavaDoc for FirebaseMessagingService doesn't mention the onNewToken method yet. It looks like not all updated documentation has been published yet. I've filed an internal issue to get the updates to the reference docs published, and to get the samples in the guide updated too.

In the meantime both the old/deprecated calls, and the new ones should work. If you're having trouble with either, post the code and I'll have a look.

FirebaseInstanceId.Instance.Token is depricated and returns null in Xamarin.Android using Xamarin.Firebase.Messaging

UPDATE

GetInstanceId<InstanceIdResult>() is also deprecated in favour of FirebaseMessaging.getToken() for FCM Token and FirebaseInstallations.getId() for Instance Identifier,

Sample Image

So, FirebaseMessaging.getToken() is the recommended way now to get the FCM Token,

This is how you can consume it easily,

var token = await FirebaseMessaging.Instance.GetToken();

and FirebaseInstallations.getId() is the recommended way now to get the Instance Identifier,

This is how you can consume it easily,

var id = await FirebaseInstallations.Instance.GetId();

here, var is of the Type Java.Lang.Object. Do, token.ToString() to get the string value.

ORIGINAL

FirebaseInstanceId.Instance.Token is deprecated in favour of GetInstanceId<InstanceIdResult>(),

Sample Image

So, GetInstanceId<InstanceIdResult>() is the recommended way,

This is how you can consume it,

var instanceIdResult = await FirebaseInstanceId.Instance.GetInstanceId().AsAsync<IInstanceIdResult>();
var token = instanceIdResult.Token;


Related Topics



Leave a reply



Submit