简体   繁体   English

Flutter Firebase:从云函数发送通知

[英]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.

相关问题 在 firebase 云函数 flutter 中发送计划 email - Send schedule email in firebase cloud functions flutter flutter:是否可以使用 FCM 和云功能离线发送推送通知? - flutter: is it possible to send push notifications offline using FCM and cloud functions? Flutter 通知与 Firebase 云消息传递 - Flutter Notifications with Firebase Cloud Messaging 使用 Flutter 和 Firebase 发送通知 - Send notifications using Flutter and Firebase firebase 推送通知的云功能不工作 - firebase cloud functions for push notifications are not working 为什么我需要将管理 SDK 与 Cloud Functions 结合使用才能在 Flutter 中使用 FCM 向其他设备发送通知? - Why do I need to use admin SDK with Cloud Functions to send notifications to other device using FCM in Flutter? (颤振)如何使用 Firebase 的 Cloud Functions 从 Firestore 检索文档 - (Flutter) How to retrieve document from Firestore using Cloud Functions for Firebase Flutter + Firebase云功能-如何从HttpsCallableResult获取数据 - Flutter + Firebase Cloud Functions - How to get data from HttpsCallableResult Flutter:无法发送 Firebase 推送通知 - Flutter : Unable to send Firebase push notifications Flutter 带有 Cloud Functions 和 Cloud Messaging 的 Firestore 新文档的通知 - Flutter Notifications on Firestore new document with Cloud Functions and Cloud Messaging
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM