如何安排推送通知以响应本机博览会? [英] How to schedule push notifcations for react native expo?

查看:109
本文介绍了如何安排推送通知以响应本机博览会?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在计划的时间向用户发送推送通知.假设他们为活动设置了日期,并且希望在30分钟之前收到通知,也就是我想向他们发送通知的时间.我正在使用firebase作为后端,并且该项目是使用expo构建的.

我很好奇,如果我使用Firebase云消息传递,我将如何使用expo的通知系统,因为它说我需要来自firebase的单独权限(我已经为每个用户拥有expo令牌).我已经研究了节点cron/schedule以及react-native推送通知,但是我不确定哪个将是最佳解决方案以及在哪里部署该解决方案(例如运行云功能).

我假设我需要某种类型的函数,该函数需要令牌,消息正文,标题和日期,然后对其进行设置以将其调度到服务器或本地.然后,当他们按下按钮以接收通知时,将调用该函数.他们还可以更改事件的日期,因此,如果用户这样做,则需要更改日期.

任何建议都将不胜感激,因为我已经对此进行了数天的研究,但仍然不确定最佳方法.

解决方案

一种可能的方法:

  1. 在您的后端中,安排每分钟(或每15秒)运行一次cron作业,并对照数据库检查哪些事件的开始时间在接下来的30分钟之内.

  2. 一旦您拥有events,请找出为这些事件注册的用户并收集其用户ID.

  3. 正如您提到的那样,您已经存储了令牌,因此我假设这些令牌针对用户ID存在于某些表中. (例如user-idtokens的映射).查找此表以获取这些用户的令牌.

  4. 准备通知payload并调用firebase消息传递以发送针对令牌的通知.例如,此时,您可以调用 Firebase SDK中的sendToDevice() 函数:firebase.messaging().sendToDevice(tokens, payload);

现在您可以在后端(例如Nodejs)中实现这些步骤,也可以为此部署云功能并设置 解决方案

One possible approach:

  1. In your backend, schedule a cron job that runs every minute (or every 15 seconds) and checks against database which events have start time within next 30 mins.

  2. Once you have the events, find out the users registered for those events and collect their user ids.

  3. As you mention that you already have stored the tokens, so I assume that those tokens exist in some table against the user id. (e.g. mapping of user-id and tokens). Look up this table to fetch the tokens of those users.

  4. Prepare the notification payload and call firebase messaging to send notification against the token. For example, at this point you can call the sendToDevice() function from Firebase SDK: firebase.messaging().sendToDevice(tokens, payload);

Now you can implement these steps in your backend (e.g. Nodejs) or you can deploy a cloud function for this and setup scheduling for this cloud function.

Let me know if you need any further help!

这篇关于如何安排推送通知以响应本机博览会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆