URL and Link repository

Saturday, January 7, 2017

Testing Firebase Cloud Messaging

After putting all the pieces together from resources on the internet like SimplifiedCoding, I am unable to consistently send messages to the app through the Firebase Console notification feature. The message is not always displayed on the device but appears to have been sent through Firebase.

Maybe this is the problem, maybe not.

"FCM usually delivers messages immediately after they are sent. However, this might not always be possible. For example, if the platform is Android, the device could be turned off, offline, or otherwise unavailable. FCM might intentionally delay messages to prevent an app from consuming excessive resources and negatively affecting battery life. When this happens, FCM stores the message and delivers it as soon as it's feasible. While this is fine in most cases, there are some apps for which a late message might as well never be delivered. For example, if the message is an incoming call or video chat notification, it is meaningful only for a short period of time before the call is terminated. Or if the message is an invitation to an event, it is useless if received after the event has ended. You can use the time_to_live parameter, supported in both HTTP and XMPP requests, to specify the maximum lifespan of a message. The value of this parameter must be a duration from 0 to 2,419,200 seconds, and it corresponds to the maximum period of time for which FCM stores and attempts to deliver the message. Requests that don't contain this field default to the maximum period of four weeks. Here are some possible uses for this feature: Video chat incoming calls Expiring invitation events Calendar events Another advantage of specifying the lifespan of a message is that FCM never throttles messages with a time_to_live (TTL) value of 0 seconds. In other words, FCM guarantees best effort for messages that must be delivered "now or never." Keep in mind that a time_to_live value of 0 means messages that can't be delivered immediately are discarded. However, because such messages are never stored, this provides the best latency for sending notification messages."