Reputation:
I can get Firebase message in onMessage
when i'm in app like this:
{data: {}, notification: {body: how are you , title: hi}}
My code in 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;
});
I want to get Firebase message when app in background or closed, how can I get that?
Upvotes: 0
Views: 72
Reputation: 2215
All you need to know is describe in the Receiving Message section of the Firebase Messaging package.
Methods onResume
and onLaunch
methods are fires only when the user clicks on the notification
Upvotes: 1