Hum*_*ent 4 firebase firebase-cloud-messaging
我正在使用FCM进行聊天应用.每次用户收到消息时,我都会通过FCM向他发送通知.如果用户未在前台使用我的Web应用程序,则消息处理将在默认的Service Worker中进行,该Service Worker会生成一个通知,其中包含我在请求正文中指定的参数.问题是,每次发送新推送消息且应用程序处于后台时,浏览器(在Chrome和Firefox上测试)都会创建新消息,而不是更新现有消息.我想保留已经可见的通知并仅更新其值,这可能吗?
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();
Run Code Online (Sandbox Code Playgroud)
{
"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
}
}
Run Code Online (Sandbox Code Playgroud)
好的,所以我发现这显示了json主体可用的所有选项.对于我需要的东西,我只需要在我的json体中的通知obj上添加"tag"参数.如果要更新通知,请使用相同的标记发送通知.例:
{
"notification": {
"title": "",
"body": "",
"click_action": "",
"icon": "",
"tag" : "this must be the same for the notifications you want to update"
},
"to": "****",
"data": {}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1319 次 |
| 最近记录: |