Get Instant Solutions for Kubernetes, Databases, Docker and more
Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that allows you to reliably send messages at no cost. Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention.
When using Firebase Cloud Messaging, you might encounter an error with the code InvalidTtl. This error typically occurs when you attempt to send a message with an invalid time-to-live (TTL) value.
TTL, or time-to-live, is a parameter that specifies the lifespan of a message. It defines how long (in seconds) the message should be kept in FCM storage if the device is offline. Once the TTL expires, the message will be discarded.
The InvalidTtl error indicates that the TTL value provided is not within the acceptable range. FCM requires the TTL value to be between 0 and 2,419,200 seconds (28 days). If the value is outside this range, the message will not be sent, and you will receive an InvalidTtl error.
To resolve the InvalidTtl error, follow these steps:
Ensure that the TTL value you are using is within the valid range. The TTL should be an integer between 0 and 2,419,200 seconds. For example, if you want the message to be available for 1 day, set the TTL to 86400 seconds.
Review your code where the TTL is set. Ensure that the value is correctly defined and within the allowed range. Here is an example of how to set the TTL in a JSON payload:
{
"message": {
"token": "your_device_token",
"notification": {
"title": "Hello",
"body": "World"
},
"android": {
"ttl": "3600s" // TTL set to 1 hour
}
}
}
After updating your code, test the message sending process to ensure that the InvalidTtl error is resolved. You can use tools like Firebase's Send Message page to verify your setup.
For more information on setting TTL and handling other FCM errors, refer to the following resources:
(Perfect for DevOps & SREs)
(Perfect for DevOps & SREs)