php - How to prompt notification on user time set in flutter ← (PHP)

I am trying to work around it where the user can set a time and an alarm or notification will prompt when it is exactly the time set in my flutter app. I am using PHP for my backend and also FCM for my notification. Am open to any idea to achieve this.

Answer



Solution:

You can subtract the timestamp at which user wants the alarm and the current timestamp. After that you can schedule the cloud function to trigger notification at that time like for every 5 minutes:-

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
  console.log('This will be run every 5 minutes!');
  return null;
});

or you can put the time at which he wants like on 5th august 13:45 :-

exports.scheduledFunction = functions.pubsub.schedule('45 13 5 8 *').onRun((context) => {
      console.log('This will run on 5th August at 13:45!');
      return null;
    });

To understand the second pls refer schedules

Now in the function add the push notification code.

Source