【发布时间】:2021-02-19 18:54:48
【问题描述】:
我是在加拿大学习计算机编程的学生。 现在,我正在使用 Flutter/Firebase 将该应用程序作为我的副项目。
在我的应用程序中包含聊天功能。我面临的问题是如何增加徽章编号并在未阅读消息时保留它。
我在 firebase 中附上了我的 Message 数据结构的图片。
下面的代码是firebase函数代码。现在我正在使用此代码推送通知。 我成功收到通知,但问题是如何计算应用程序图标的徽章编号。正如您在通知徽章中看到的那样,编号是“1”。每当我推送通知时,该号码都会覆盖以前的号码。我认为这是错误的方式,我所期待的,如果值 isMessageRead 在firebase数据库增量徽章编号。我只是想知道逻辑方法,或者我可以研究的任何其他可以解释如何计算图标徽章编号的来源。
目前我不知道如何管理徽章编号。
感谢阅读,
我在等你的回复。
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
exports.onCreateMessage = functions.firestore.document('/Chat/{currentUserID}/UserList/{anotherUserID}/Messages/{message}')
.onCreate(async (snap, context) => {
const currentUserID = context.params.currentUserID;
const anotherUserID = context.params.anotherUserID;
console.log(currentUserID);
console.log(anotherUserID);
if (currentUserID == snap.data().recieverID) {
return admin.messaging().sendToTopic(`${currentUserID}`, {
notification: {
title: snap.data().senderID,
body: snap.data().message,
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
sound: 'default',
badge: '1'
}
});
}
});
【问题讨论】:
标签: firebase flutter firebase-cloud-messaging