Firebase instance id: deprecation of getId() in 21.0.0(Firebase 实例 ID:在 21.0.0 中弃用 getId())
问题描述
随着最近发布的 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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Firebase 实例 ID:在 21.0.0 中弃用 getId()
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- URL编码Swift iOS 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- UITextView 内容插图 2022-01-01
