1

I need to listen for update on the client side whenever something in the Firestore database changes. I need some clarification about this topic:

Let's say that we want to notify the user whenever a new document is created in a collection: We have 2 cases:

  1. when the user is on the app
  2. when the user is out of the app

for the second point I can create a cloud function firestore trigger that notifies the user through the push notification service

But on the first point I don't know which is the best approach.

(maybe setting up a snapshotListener? but how can I do that on the global scope of the app? Is it the right approach?)

1 Answer 1

1

Should you implement a FCM notification for the second scenario, the notification will be fired to your app no matter if it is on background or foreground, so you can use this approach for both situations actually.

You can use this solution to not fire a notification (on the frontend) and in case you don't want to fire that if the app is in foreground you can just keep the completionHandler() blank and that's it.

Sign up to request clarification or add additional context in comments.

6 Comments

thank you, but instead of the completion handler can I perform some operations in the UI? like presenting some custom banner
yes, you can. you can do any operation needed in fact, the mentioned code is just to show or not show the notification itself.
That's perfect thank you, one more thing, Is there a way I can get the content of the notification inside willPresent notification delegate function?
I believe all you need to do is this: let content = notification.request.content
Thank you very much, accepted answer, really appreciated your help 🙏🏻
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.