Firebase 实例 ID:在 21.0.0 中弃用 getId()

Firebase instance id: deprecation of getId() in 21.0.0(Firebase 实例 ID:在 21.0.0 中弃用 getId())
本文介绍了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()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)