gpt4 book ai didi

firebase - 如何获取Firebase通知数据?

转载 作者:行者123 更新时间:2023-12-03 04:51:43 25 4
gpt4 key购买 nike

当我在应用程序中时,可以在onMessage中获取Firebase消息,如下所示:

{data: {}, notification: {body: how are you , title: hi}}

我在 initState中的代码:

    firebaseMessaging.configure(

onLaunch: (Map<String,dynamic> msg){
print(" onLaunch called");
print(msg);
},
onResume: (Map<String,dynamic> msg){
print(" onResume called");
print(msg);

},
onMessage: (Map<String,dynamic> msg){
print(" onMessage called");
print(msg);
setState(() {
sms=msg['notification']['body'];
});
},


);
firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(
sound: true,
alert: true,
badge: true
)
);
firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings setting){
print("ios setting registed");
});
firebaseMessaging.getToken().then((token){
update(token);
});
}
update(String token){
print(token);
setState(() {
textValue=token;
});

我想在后台或关闭应用程序时收到Firebase消息,
我该怎么办?

最佳答案

您只需要在Firebase Messaging软件包的Receiving Message部分中进行描述即可。

仅当用户单击通知时,onResumeonLaunch方法的方法才触发

关于firebase - 如何获取Firebase通知数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61238051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com