简体   繁体   English

通过云功能使用其UID向多个用户发送FCM通知

[英]Send FCM Notification to multiple users using their UID through cloud functions

i have users Uid in an 'users' array as ['uid1','uid2'] now i will be sending notifications to these users in cloud function? 我现在在[用户列表]中将用户Uid设置为['uid1','uid2'],我将在云功能中向这些用户发送通知吗?

        exports.sendNotificationFromCr = functions.database.ref('/cr/{crUid}/notifications/{notificationid}/').onWrite(event => {

    const uid = ['uid1','uid2']; // some how i get this.
    // some work to send notifications
    // to all tokens of uid1 and uid2.    
}

here is the database structure: 这是数据库结构:

users/
   uid1/
      name:{name}
      FCM-key/
         token1:true
         token2:true
   uid2/
      ...
      FCM-key/
         token3:true

using ['uid1','uid2'] i want to send notification to all 3 tokens in my database. 我想使用['uid1','uid2']将通知发送到数据库中的所有3个令牌。 how to do that? 怎么做?

If you're using something like firebase. 如果您使用的是Firebase之类的工具。 Then you would want to have a notifications database model, that has the userId, the notification title, body and perhaps image, also a seen flag (true or false). 然后,您将需要一个通知数据库模型,该模型具有userId,通知标题,正文以及图像,以及可见标志(是或否)。

You would then post notifications either from your clients or from your cloud server code into the database. 然后,您可以将来自客户端或云服务器代码的通知发布到数据库中。 One per client/notification. 每个客户/通知一个。 If you have thousands of users you would use some sort of server-side cronjob, to offload this so that it runs outside of say your client to server API. 如果您有成千上万的用户,则可以使用某种服务器端的cronjob来卸载它,以便它在客户端到服务器API之外运行。

On the clients, you would be listening for new rows in that model filtering on the userId and when they appear, display them to the client in your UI. 在客户端上,您将在该模型中根据userId监听新行,并在新行出现时在用户界面中将其显示给客户端。 Once the client has seen the notification you would mark it as seen on the client. 客户端看到通知后,您将其标记为在客户端上看到。

Without knowing what platforms, code base, DB you are using it's impossible to explain in code terms how this would be done. 如果不知道您使用的平台,代码库和数据库,就无法用代码术语解释如何实现。

There are various API's for IOS and Android and Firebase that resolve this. 有多种针对IOS,Android和Firebase的API可以解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在flutter中使用javascript云函数发送fcm通知? - How to send a fcm notification using javascript cloud functions in flutter? 如何使用Firebase云功能将通知发送到多个设备令牌 - How to send notification to multiple device token using firebase cloud functions Firebase的云功能-将FCM消息发送到多个令牌 - Cloud Functions for Firebase - Send FCM message to multiple tokens 如何使用 firebase 中的云函数向 uid 发送值? - How can I send a value to uid using cloud functions in firebase? 将用户 UID 发送到 firebase 云函数是否安全 - Is it secure to send the user UID to firebase cloud functions 如何使用 FCM 发送通知? - How to send notification using FCM? 使用 Firebase 云函数从 firebase 发送推送通知 - Send push notification From firebase by using Firebase cloud Functions 使用Cloud Functions for Firebase向特定用户发送通知 - Send notification using Cloud Functions for Firebase to specific user 具有 Firebase 实时数据库的云功能未触发 onCreate 且未发送 FCM 通知 - Cloud functions with Firebase Realtime Database not triggering onCreate and not sending FCM notification 通过 firebase 云函数向 web 应用发送 FCM 消息 - Sending FCM messages to web apps through firebase cloud functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM