随着最近发布的 FirebaseInstanceId 和 FirebaseCloudMessaging (21.0.0
) Firebase 已弃用 iid
包以及 getToken()
和 >getId()
方法现已弃用.
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.
根据 Firebase 发行说明 方法 getToken()
移至 FirebaseMessaging
之前:
FirebaseInstanceId.getInstance().getToken()
之后:
FirebaseMessaging.getInstance().getToken()
使用 fcmToken
,但要检索 instance id,FirebaseMessaging 和 FirebaseInstanceId 中没有可用的方法.
Which gives use the fcmToken
, but to retrieve instance id, there's no method available in FirebaseMessaging nor FirebaseInstanceId.
那么,instance_id
是否被认为是无用的id,不应该再使用了?还是有替代品?
So, Is instance_id
considered a useless id and should no longer be used? or is there a replacement for this?
FirebaseInstanceId 类已弃用,获取令牌使用 FirebaseMessagingClass.可以使用以下代码生成令牌:
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();
}
});
关于Firebase InstanceId,官方文档是这样说的:
Regarding the Firebase InstanceId, this is what the official document says:
公共任务getInstanceId()->此方法已弃用.对于实例标识符,请改用 FirebaseInstallations.getId().对于 FCM 注册令牌,请改用 FirebaseMessaging.getToken().
public Task getInstanceId () -> This method is deprecated. For an instance identifier, use FirebaseInstallations.getId() instead. For an FCM registration token, use FirebaseMessaging.getToken() instead.
这篇关于Firebase 实例 ID:在 21.0.0 中弃用 getId()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!