Search code examples
javascriptandroidfirebasegoogle-cloud-firestoreeventtrigger

Push notification when app is in foreground (using Firebase triggers)


Let's say that there is an update in certain collection and it triggers function that "exports" notification for certain user (token). I have implemented Firebase Functions in JavaScript for Firestore Triggers (onCreate, onUpdate,...) and it works if app is in background.

I want to send a notification whether the application is running or not... Can user receive notification (lets say onUpdate) if app is in foreground or that feature is not ready yet (since triggers are in beta version)?

Thanks in advance


Solution

  • If depends on whether your message contains a data property, a notification property, or both.

    If the message only contains a notification property, it'll delivered to your application code if the app is in the foreground, but handled by the system when the app is in the background.

    If your message contains a data property, it'll always be delivered to your application code. If it also contains a notification property, that part will be handled by the system when the app is in the background.

    For more on this, see the Firebase documentation on message types.