简体   繁体   English

我在我的 flutter 应用程序中使用 firebase 消息传递,但是当我运行我的项目时,它显示 Stringtoken=FirebaseInstanceId.getInstance().getToken(senderId, "*");

[英]I'm using firebase messaging in my flutter app but when I run my project it show Stringtoken=FirebaseInstanceId.getInstance().getToken(senderId, "*");

I'm using firebase messaging in my flutter app but when I run my project it show String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");我在我的 flutter 应用程序中使用 firebase 消息,但是当我运行我的项目时它显示 String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");

when I run my application it shows this error in the console:当我运行我的应用程序时,它在控制台中显示此错误:

C:\Users\cerbi\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java:166: error: cannot find symbol String token = FirebaseInstanceId.getInstance().getToken(senderId, "*"); C:\Users\cerbi\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_messaging-9.1.4\android\src\main\java\io\flutter\plugins\firebase\messaging\FlutterFirebaseMessagingPlugin.java :166: 错误:找不到符号 String token = FirebaseInstanceId.getInstance().getToken(senderId, "*"); ^ symbol: variable FirebaseInstanceId location: class FlutterFirebaseMessagingPlugin Note: Some input files use or override a deprecated API. Note: Recompile with -Xlint:deprecation for details. ^ 符号:变量 FirebaseInstanceId 位置:class FlutterFirebaseMessagingPlugin 注意:一些输入文件使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息。

What went wrong: Execution failed for task ':firebase_messaging:compileDebugJavaWithJavac'.出了什么问题:任务“:firebase_messaging:compileDebugJavaWithJavac”的执行失败。

and when I navigate to the specific file stated in the error message here is the code in there当我导航到错误消息中所述的特定文件时,这里是其中的代码

        private Task<Map<String, Object>> getToken(Map<String, Object> arguments) {
            return Tasks.call(
                cachedThreadPool,
                () -> {
                  String senderId =
                      arguments.get("senderId") != null
                          ? (String) arguments.get("senderId")
                          : Metadata.getDefaultSenderId(FirebaseApp.getInstance());
                  String token = FirebaseInstanceId.getInstance().getToken(senderId, "*");
                  return new HashMap<String, Object>() {
                    {
                      put("token", token);
                    }
                  };
                });
          }

What can I do to resolve this problem, it seems that the existing code is not working anymore我该怎么做才能解决这个问题,现有代码似乎不再起作用了

You should use你应该使用

FirebaseMessaging.getInstance().token

to get token, since获得令牌,因为

FirebaseInstanceId.getInstance().getToken

is deprecated.已弃用。

To retrieve the current registration token for an app instance, you need to call FirebaseMessaging.instance.getToken();要检索应用程序实例的当前注册令牌,您需要调用FirebaseMessaging.instance.getToken(); as stated here in their official guide.正如他们官方指南中所述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter,当我从 firebase 消息发送通知时出现此错误并且我的应用程序冻结 - Flutter, when i send notification from firebase messaging i get this error and my app freeze 我在部署项目时遇到 firebase 问题 - I'm having a problem with firebase when i deploy my project 当我运行项目时,我的 flutter 项目启动画面冻结可能是由于代码中的 firebase 错误 - My flutter project splashscreen is freezing when I run the project maybe due to firebase error in the code 为什么我的 flutter 应用在 iOS 上运行时没有使用 Firebase 云消息接收通知? - Why my flutter app doesn't receive notifications using Firebase Cloud Messaging when running on iOS? 为什么我无法将我的 flutter iOS 应用程序添加到我的 firebase 项目中? - Why am I unable to add my flutter iOS app to my firebase project? 我正在处理一个 flutter web 项目,当我在本地主机上运行时它工作正常但在 firebase 中部署后它显示白色空白页 - I'm working on a flutter web project ,when i run in localhost it is working fine but after deploying in firebase it is showing white blank page Firebase:如何在应用检查中注册我的 Flutter 应用? - Firebase: How do I register my Flutter app in app check? 我正在使用 firebase 在 Flutter 中创建一个杂货应用程序,但我无法向文本小部件显示更新的购物车值 - I'm creating an grocery app in Flutter with firebase but i am unable show the updated cart value to text widget 我的 Flutter 应用程序可以使用“Firebase 存储”的哪个替代方案? - Which alternative to "Firebase Storage" could I use for my Flutter App? 我正在尝试将我的简单 typescript 应用程序部署到 firebase 云功能。 但我有这个错误 - I'm trying to deploy my simple typescript app to firebase cloud functions. But I have got this error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM