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

huangapple go评论69阅读模式
英文:

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

问题

我在我的Flutter应用中使用Firebase消息传递,但当我运行我的项目时,它显示以下代码并在控制台中显示以下错误:

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: error: cannot find symbol
          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.

What went wrong:
Execution failed for task ':firebase_messaging:compileDebugJavaWithJavac'.

当我导航到错误消息中指定的特定文件时,其中的代码如下:

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);
                }
            };
        });
}

如何解决这个问题?似乎现有的代码不再起作用。

【注意】请注意,这是代码和错误消息的翻译,不包括答案或解决方案。

英文:

I'm using firebase messaging in my flutter app but when I run my project it show 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, "*");
^
symbol: variable FirebaseInstanceId
location: class FlutterFirebaseMessagingPlugin
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

What went wrong:
Execution failed for task ':firebase_messaging:compileDebugJavaWithJavac'.

and when I navigate to the specific file stated in the error message here is the code in there

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

What can I do to resolve this problem, it seems that the existing code is not working anymore

答案1

得分: 1

你应该使用

FirebaseMessaging.getInstance().token

来获取令牌,因为

FirebaseInstanceId.getInstance().getToken

已经被弃用。

英文:

You should use

FirebaseMessaging.getInstance().token

to get token, since

FirebaseInstanceId.getInstance().getToken

is deprecated.

答案2

得分: 1

要检索应用程序实例的当前注册令牌,您需要调用FirebaseMessaging.instance.getToken();,如其官方指南此处所述。

英文:

To retrieve the current registration token for an app instance, you need to call
FirebaseMessaging.instance.getToken(); as stated here in their official guide.

huangapple
  • 本文由 发表于 2023年1月9日 01:06:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75049770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定