How to schedule push notifcations for react native expo?

后端 未结 1 1178
情书的邮戳
情书的邮戳 2021-01-29 04:18

I am trying to send push notifications to a user at a scheduled time. Say they set the date for an event and they want to be notified 30 minutes before, that is when I would lik

相关标签:
1条回答
  • 2021-01-29 05:06

    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!

    0 讨论(0)
提交回复
热议问题