英文:
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<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
答案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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论