Reputation: 183
We are using Firebase cloud messaging. Sometimes when Android or iOS app is in sleep mode the cell phone receives same (duplicates) notifications messages. For device identifications the FIRInstanceID token is used. An external server on node.js is used for sending notifications to Firebase service. No duplications in our server log file are presented.
Upvotes: 12
Views: 16790
Reputation: 563
If you are working with Firebase-sw.js then here is what is happening.
"Note this is not for admin SDK"
When you send "notification" key in the payload it triggers the default behaviour of the of the browser and it shows the notification. Then in your service provider you are showing the notification again:
self.registration.showNotification(notificationTitle,notificationOptions)
...You are not at fault because the firebase documentation did not mention any details about it.
Solution You have to remove the "notification" key from your payload and modify your firebase-sw.js file like this:
messaging.onBackgroundMessage(function(payload) {
console.log('Received background message ', payload);
const notificationTitle = payload.data.title;
const notificationOptions = {
body: payload.data.body
};
self.registration.showNotification(notificationTitle, notificationOptions);
});
and your payload should look like this:
{
"data": {
"title":"New Ride Request",
"body":"A new ride has been requested",
"sound" : "default"
},
"condition": "'topic1' in topics"
}
Now your default notification will not trigger and your code level notification will be displayed only.
Upvotes: 1
Reputation: 21
I had the same problem today with my app, after several hours of debuging it seems that the problem is the payload am sending:
{
"registration_ids":["token", "token2",...],
"data":{
"title":"notification title",
"body":"notification body",
"screen":"product",
"id":1
},
"android":{
"ttl":"1000s",
"priority":"high",
"notification":null //<= set notification to null
}
}
After setting notification to null , no dupicate notifications.
Upvotes: -1
Reputation: 83
in file firebase-messaging-sw.js
comment this line
// self.registration.showNotification(notificationTitle,notificationOptions)
and no duplicate fcm anymore
Upvotes: 2
Reputation: 442
check this answer, That worked for me... https://stackoverflow.com/a/44435980/1533285
I was requesting permissions to GCM too so Systray showed two notifications.
Upvotes: 0