Home > Mobile >  Schedule FCM Notification using HTTP V1
Schedule FCM Notification using HTTP V1

Time:10-19

So i'm migrating to FCM HTTP v1 to send notification. But does it comes with scheduled notification configuration?

I want to send notification, for example like one hour from now (for use case like reminder).

In earlier version, like exampled here, you can just provide configuration like this:

{ 
  "to": "/topics/discount-offers", 
  "priority": "high",
  "data" : {
    "title" : "TITLE_HERE",
    "message" : "MESSAGE_HERE",
    "isScheduled" : "true",
    "scheduledTime" : "2019-12-13 09:41:00"
  }
}

But after reading the documentation, I don't think there's variable to configure scheduled notification.

CodePudding user response:

The Firebase Cloud Messaging API to send messages doesn't support (and has never supported) a way to schedule the delivery of messages. If you want to schedule the display of a notification, you will need to:

  • Either run a server-side component that does the scheduling, and calls the FCM API at the right time.
  • Or call the FCM API right away, but then hold the message in your application code on the receiving device and display the notification when it's time.

The library that you used is an implement of the second option. So the isScheduled and scheduledTime properties are handled by the FCM-OnDeviceNotificationScheduler package, which uses it to schedule a local alarm.

While the v1 API to send messages has changed, you can still pass the exact same data to it - which will then be delivered to the application code on Android, where the library will use it to display the notification at the requested time.

  • Related