We are using FCM to send push notifications to our app on android devices. The devices are able to receive all the notifications when they are online (background and foreground). But we are facing one issue. If the device is in offline mode (turn off WiFI) and if our server send multiple notifications (more than 1), and if we turn the device back to online (turn on WiFI) after 10 mins (not 4 weeks), the device is receiving only last notification instead of receiving all the pending notifications.
As per the firebase documentation, "If the device is not connected to GCM, the message will be stored until a connection is established (again respecting the collapse key rules). When a connection is established, GCM delivers all pending messages to the device. If the device never gets connected again (for instance, if it was factory reset), the message will eventually time out and be discarded from GCM storage. The default timeout is 4 weeks, unless the time_to_live flag is set." We are not setting ttl values while sending notifications to firebase and we are not using collapsible messaging. So the default values for ttl should be 4 weeks and all are non collapsible messages. But still devices are receiving only last message when they come back online.
Below is the server code (javascript) where we are sending notifications to devices using firebase.
const admin = require('firebase-admin');
const serviceAccount = require("./ServiceAccountKey_Nightly.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "XXXXXXXX"
});
const mobileToken = "xxxxxxxxxxxxxxxxxxxxxx";
const message = {
token: mobileToken, // To send device-level message
data: {
message: "Test!",
notification: {
title: 'Notification from server - x', // Changing x value every time when I send message
body: 'Server notification - x'
},
};
// Send a message to devices subscribed to the provided topic.
admin.messaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
Can any one please let me know if I need to set any additional parameters while sending notification or did Firebase change any thing regarding notification delivery when devices come back online.
Note:
I already went through lot of online tutorials and stack overflow questions like below. None helped to understand the issue