[英]Flutter Firebase: Send notifications from cloud functions
I have a collection, 'users', where each document holds an int votesUseable.我有一个集合,“用户”,其中每个文档都包含一个 int votesUseable。 I have a cloud function setup to reset all users votes everyday:我有一个云 function 设置来每天重置所有用户的投票:
export const resetDay = functions.pubsub.schedule("00 22 * * *")
.timeZone("America/New_York")
.onRun(async () => {
await admin.firestore().collection("users")
.get().then((querySnapshot) => {
querySnapshot.forEach(async (doc) => {
// eslint-disable-next-line max-len
await doc.ref.update({"votesUsable": 2});
});
})
.catch((error) => {
console.log("Error getting documents: ", error);
});
return null;
});
Id like to add a push notification sent to each user, however I am having trouble implementing it.我想添加一个发送给每个用户的推送通知,但是我在实现它时遇到了麻烦。 I am trying to follow the documentation example: https://github.com/firebase/functions-samples/blob/main/fcm-notifications/functions/index.js , however it feels very different from the way I implemented the function.我正在尝试遵循文档示例: https://github.com/firebase/functions-samples/blob/main/fcm-notifications/functions/index.js ,但是感觉与我实现 function 的方式非常不同。 Does anyone have any ideas?有没有人有任何想法? Im also using this with a flutter app, if that makes a difference.我还将它与 flutter 应用程序一起使用,如果这有所作为的话。 Thank you谢谢
If you're wondering about the code that loads the tokens from the database, the example you linked reads them from the Realtime Database while you read them from Firestore.如果您想知道从数据库加载令牌的代码,您链接的示例会在您从 Firestore 中读取它们时从实时数据库中读取它们。 While both databases are part of Firebase, they are completely separate and have a quite different API.虽然这两个数据库都是 Firebase 的一部分,但它们是完全独立的,并且具有完全不同的 API。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.