Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to expire fcm push notifications or set lifetime?

My application sending push notifications from the server to several user devices. Notification will valid for a certain time period in my app scenario. currently, all notifications go through my app, but I don't send this at all after given expiration time. Code to send on a user.

   {
      "to":"REGISTRATION_ID",  // "to" replaces "registration_ids"
     "notification": {
        "title": "Portugal vs. Denmark”,
        "body”: "5 to 1”
      },
      "time_to_live":"600"
}

Note: "time_to_live" attribute not works.

like image 319
Md Shihab Uddin Avatar asked Nov 23 '17 06:11

Md Shihab Uddin


People also ask

Do push notifications expire?

Your push notifications certificates are generally only valid for one year.

How long FCM server can store the notification message and try to deliver?

The value must be a duration from 0 to 2,419,200 seconds (28 days), and it corresponds to the maximum period of time for which FCM stores and attempts to deliver the message.

Is FCM always free?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.

Can FCM notification on Android overwrite previous one?

If specified and a notification with the same tag is already being shown, the new notification replaces the existing one in the notification drawer.


2 Answers

You should use the following as per this documentation: Setting the lifespan of a message.

"android": {
  "ttl":"600s"
}

instead of

"time_to_live":"600"
like image 153
Ayman Avatar answered Sep 19 '22 17:09

Ayman


You should set it as numeric:

"time_to_live": 600
like image 36
mohsen Avatar answered Sep 20 '22 17:09

mohsen