我们正在使用Firebase云消息传递。有时候,当Android或iOS应用程序处于睡眠模式时,手机会收到相同的(重复的)通知消息。为了设备识别,使用FIRInstanceID令牌。一个基于node.js的外部服务器用于向Firebase服务发送通知。在我们的服务器日志文件中没有重复出现的记录。
我们正在使用Firebase云消息传递。有时候,当Android或iOS应用程序处于睡眠模式时,手机会收到相同的(重复的)通知消息。为了设备识别,使用FIRInstanceID令牌。一个基于node.js的外部服务器用于向Firebase服务发送通知。在我们的服务器日志文件中没有重复出现的记录。
在文件firebase-messaging-sw.js中
注释掉这行代码
// self.registration.showNotification(notificationTitle,notificationOptions)
这样就不会有重复的fcm了
self.registration.showNotification(notificationTitle,notificationOptions)
...你没有错,因为firebase文档没有提及任何细节。
解决方案 您需要从负载中删除“notification”键,并像这样修改firebase-sw.js文件:
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);
});
你的有效载荷应该长这样:
{
"data": {
"title":"New Ride Request",
"body":"A new ride has been requested",
"sound" : "default"
},
"condition": "'topic1' in topics"
}
现在您的默认通知将不会触发,只会显示代码级别的通知。
看一下这个答案,对我有用... https://dev59.com/Z57ha4cB1Zd3GeqPq_O3#44435980
我也正在请求GCM的权限,所以Systray显示了两个通知。
今天我用我的应用程序遇到了同样的问题,经过几个小时的调试,似乎问题出在我发送的负载上:
{
"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
}
}
将通知设置为 null 后,不会出现重复通知。