当我在应用程序中时,可以在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部分中进行描述即可。
仅当用户单击通知时,onResume
和onLaunch
方法的方法才触发
关于firebase - 如何获取Firebase通知数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61238051/