Tom
Tom

Reputation: 6004

Is it possible to send messages through Firebase Cloud Messaging (FCM) to offline users?

I'm working on a Progressive Web App (PWA) and I need to send important reminders through push messages. Users should receive them even if they are offline. Is it possible to use Firebase Cloud Messaging (FCM) for that (maybe preload the messages or something like that?) or do I need to get a different route for offline?

Upvotes: 6

Views: 2376

Answers (1)

Renaud Tarnec
Renaud Tarnec

Reputation: 83181

Adapted after AL's comments below and Frank's comment above

It is possible to send "push messages" via Firebase Cloud Messaging (FCM) to a device that is offline, BUT the user will only see the message when the device is online again. If the device is offline it cannot receive immediately any (push) message from the "external world". If you want to trigger some reminders that are immediately visible for a device which is offline, you will have to do it locally, on the device, and not by relying on a push from the "external world".

So, having said that, if you want to use Firebase Cloud Messaging to send messages, you can do it by using Cloud Functions, i.e. from a "trusted environment". Have a look at this official Firebase Cloud Function sample: https://github.com/firebase/functions-samples/tree/master/fcm-notifications

You could trigger this Cloud Function when e.g. a new item is saved in the database (Real Time Database or Firestore), or an existing one is modified/deleted, or a file is uploaded to Storage, etc.

Upvotes: 4

Related Questions