如何获取“应用实例ID";在Flutter [英] How to get "Apps Instance Id" in Flutter
问题描述
我想在Flutter应用上设置 firebase应用内消息传递.
i want to setup firebase inapp messaging on my flutter apps.
first, it need FirebaseInstanceId
as explained here, so i can test send message to my device.
不过,该文档并未详细说明如何在Android上(尤其是在flutter上)获取它.
However the document does not tell more detail how to get it on Android, especially on flutter.
有什么主意吗?
注意:有人声称他可以扑朔迷离地使用 inapp-messaging ,请参阅
Note : someone has claimed that he can use inapp-messaging in flutter, please see here
先谢谢您...
推荐答案
可以使用 getInstanceId .
在撰写本文时,我还不知道有一个独立的插件可以执行此操作,这意味着您有两个选择:
At the time of writing, I am not aware of a standalone plugin that does this, meaning that you have two options:
- 编写您自己的插件,包装这些方法的本机实现
- 使用 firebase_messaging Flutter插件,该插件恰巧通过其getToken()方法公开了实例ID
- Write your own plugin that wraps the native implementations of those methods
- Use the firebase_messaging Flutter plugin that happens to expose the Instance ID via its getToken() method
如果您使用firebase_messaging路由(请注意,这意味着您要添加另一个依赖项),则可以执行以下操作:
If you go the firebase_messaging route (mind you, it means you're adding another dependency), you can do something like this:
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
然后在代码中的某处:
var token = await _firebaseMessaging.getToken();
print("Instance ID: " + token);
更新
调用获取令牌时,您会得到以下格式的内容: NNNNNNN:MMMMMMMMMMMMMMMMMMMM .仅使用冒号( NNNNNNNN )之前的第一部分-这是测试应用内消息传递活动所需的实例ID.
When you call get token, you get something in the following format: NNNNNNN:MMMMMMMMMMMMMMMMMM. Take only the first part before the colon (NNNNNNNN) - this is the instance ID you need to test your In-App Messaging campaign.
这篇关于如何获取“应用实例ID";在Flutter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!