【发布时间】:2017-09-28 07:17:52
【问题描述】:
我正在将 FCM 用于聊天应用。每次用户收到消息时,我都会通过 FCM 向他发送通知。如果用户不在前台使用我的 Web 应用程序,则消息处理发生在默认服务工作人员中,该服务工作人员使用我在请求正文中指定的参数生成通知。问题是,每次发送新的推送消息并且应用程序处于后台时,浏览器(在 Chrome 和 Firefox 上测试)都会创建新消息而不是更新现有消息。我想保留已经可见的通知,只更新它的值,这可能吗?
在应用不在前台时处理推送的 Service Worker:
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
firebase.initializeApp({
'messagingSenderId': '*****'
});
const messaging = firebase.messaging();
发送到 FCM 服务器的请求的 JSON 正文
{
"priority" : "normal",
"collapse_key": "demo",
"notification": {
"title": "Felicius Humble",
"body": "This is a sample message content",
"click_action": "https://****.herokuapp.com",
"icon": "****"
},
"to": "****",
"data": {
"id": 7,
"timestamp": 1493573846692,
"content": "teste",
"type": "MESSAGE",
"direction": "OUTPUT",
"sender": {
"id": 5,
"name": "Felicius Humble",
"email": "****@gmail.com",
"gender": "MALE",
"picture": "****",
"facebookID": "****",
"fcmToken": "****",
"accessToken": "****"
},
"chatID": 3
}
}
【问题讨论】:
标签: firebase firebase-cloud-messaging