flutter - 当应用程序通过使用 firebase_messaging 的推送通知终止时如何接收自定义数据?
问题描述
如标题所示,当用户在应用程序终止时单击通知时接收自定义数据的当前解决方法是什么?
似乎在 Android上无法在 onLaunch 中接收数据消息(这是理想的方式)在 IOS 上我还没有尝试过,因为我首先遇到了这个问题。
有什么线索吗?
附加信息:我通过 a 发送的通知firebase cloud function
采用以下形式:
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}
https://firebase.google.com/docs/cloud-messaging/concept-options
在onResume
我能够执行一个动作,但onLaunch
似乎没有被调用。
解决方案
我认为,您已经在启动时获得了数据,只需要稍等一下。我写它是因为我遇到了同样的事情。
你可以试试这个,
firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) async { .. },
onResume: (Map<String, dynamic> message) async { .. },
onLaunch: (Map<String, dynamic> message) async {
WidgetsBinding.instance.addPostFrameCallback((_) {
Timer(const Duration(seconds: 7), () {
// your process...
});
});
},
);
同样在我的情况下,我就这样使用它并解决了。
onLaunch: (Map<String, dynamic> message) async {
WidgetsBinding.instance.addPostFrameCallback((ignored) {
Timer.periodic(const Duration(seconds: 1), (timer) {
if (CurrentUser.currentUser != null) {
timer.cancel(); // important **
// redirect process with post details inside data
if (message['data']['type'] == NotifTypes.NEW_POST)
goGroupAndPost(Map.from(message['data']));
}
});
});
},
推荐阅读
- python - Python Regular Exression assistance
- crystal-reports - Paper orientaion is being changed in crystal report
- mysql - Get specific field Data backup along with Update query in mysql
- ios - Present uiviewcontroller from ParentViewController in Swift 4
- go - 从 Go 中的实例打印结构定义
- http-headers - Elixir Guardian 自定义标头验证而不是授权
- c - 创建一个函数,清除二维数组中的每个位置,并将其设为默认的“_”字符单元格
- apache - 此快捷方式引用的 xampp-control.exe 已更改
- java - Java从文件读取字母到多维数组
- .net - f# 不安全的内存映射文件访问