-
Notifications
You must be signed in to change notification settings - Fork 408
Description
- Operating System version: Windows 10
- Firebase SDK version: 6.0.0
- Firebase Product: Cloud Messaging
[REQUIRED] Step 3: Describe the problem
When sending a notification using messaging().send()
with the notification
parameter set and the client iOS/Android app is in the background or closed, I expect the notification to be sent to the device's notification center/drawer instead of being handled by the app. This seems to be how it works when using the legacy method sendToDevice()
. When trying to do the same with the new API though, while the notification is retrieved when the app is in the foreground, when the app is in the background or closed the notification does not get handled at all. It doesn't get caught by the app and it isn't sent to the device's notification center/drawer.
The difference I've noticed is that the newer send()
method sends a RemoteMessage
object no matter what I set the message payload to, whereas sendToDevice()
sends a Notification
object when the notification
field is set in the payload. Perhaps this is why the notifications aren't being sent to the device's notification center? I can't use the legacy API though because it's missing features that I need.
How do I get the behaviour that I want with the newer API? Am I doing something wrong with how I'm creating the messages?
Relevant Code:
The following code does not send a notification to the client device's notification center when the app is in the background or closed:
const message = {
notification: {
title: "Title,
body: "Body",
},
token: [token],
};
admin.messaging().send(message)
.then((response) => {
console.log('Successfully sent message:', response);
}).catch((error) => {
console.log('Error sending message:', error);
});
However, this does:
const message = {
notification: {
title: "Title,
body: "Body",
}
};
admin.messaging().sendToDevice([token], message)
.then((response) => {
console.log('Successfully sent message:', response);
}).catch((error) => {
console.log('Error sending message:', error);
});