像这样在应用中时,我可以在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消息, 我该怎么办?
答案 0 :(得分:1)
您需要了解的所有信息都在Firebase Messaging软件包的Receiving Message部分中进行了说明。
仅当用户单击通知时,方法onResume
和onLaunch
会被触发