iosswiftfirebase-cloud-messaging

Notifying an App user When a Cloud Firestore Document is updated


So, in my current App (iOS), I have a relationship between two separate users who need to notify each other when they update a particular Cloud Firestore document (basically a flag field that indicates that another document full of "items" is final and needs to be acted upon). I'm thinking there is a way to do this through FCM but I've never used this before. Is there a way for a particular user to trigger a notification so that the other user they're linked to (1-to-1 relationship) can be notified? Sorry, this is kind of new to me. I'm used to doing a lot with local notifications but not so much with push notifications and/or cloud functions. Before possibly going down the wrong path here, I wanted to ask about this and get recommendations if possible. Any help/ideas would be greatly appreciated :)


Solution

  • There is nothing built directly into FCM to notify a user upon a specific database change, but you can of course call the FCM API to send a message when you detect such a change.

    The most important thing to keep in mind is that the FCM API to send messages can only be securely called from a trusted environment, such as your development machine, a server that you control, or Cloud Functions.

    For an example of sending a notification upon a database change with Cloud Functions, see the documentation on Notifying users when something interesting happens.

    Also see: