0

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 :)

KatM
  • 57
  • 11
  • An app doesn't send a notification through FCM to itself. – El Tomato Jul 20 '21 at 00:08
  • So, what's the best way to notify a user (customer) from another user (company) that a cloud firestore document has been updated and needs to be reviewed/acted on? I thought that in a case like this, the company could update the document and that a notification could somehow get triggered and then get sent to the customer. Not the case? – KatM Jul 20 '21 at 00:34

1 Answers1

3

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:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Thank you for your response. So, if I'm understanding this correctly, I need to have a cloud function set up that gets triggered when the document gets updated, and then it'll send a notification via FCM. Is that right? Sorry to ask such basic questions. I've used Firebase before but not with notifications or functions. It looks kind of complicated. Is it difficult to set up a cloud function trigger? Where should I even start? Can you give me a summary of the steps I need to take? – KatM Jul 20 '21 at 23:11
  • I looked at the link "notifying users when something interesting happens" and that's a good description generally but I'm getting confused as far as what I need to install, code, and test with my project. I was able to push a notification via the console but I need notifications to be triggered when each user updates that document. Kind of think - "tag, you're it" kind of thing. – KatM Jul 20 '21 at 23:16
  • That's exactly what the first example I linked does. It's a complex use-case, so the code is indeed more involved than what you may be used to. If you run into a specific problem, we may be able to help if you post a new question with the [minimal, complete/standalone code that reproduces where you got stuck](http://stackoverflow.com/help/mcve) (read this link too please, as it's quite useful and increases the chances someone can help). – Frank van Puffelen Jul 21 '21 at 05:03
  • 1
    Thank you! I will take a look and post if I get stuck. I just wanted a brief understanding and to know whether or not what I want to do is possible/logical. I didn't want to waste a ton of time going down the wrong road :) – KatM Jul 21 '21 at 12:41
  • I'm seeing a lot of stuff out here about using Flutter to send to APNs. You also have comments in a lot of these and other posts with regard to security risks. I want to make sure that my notifications are secure. That being said, is using Flutter a viable option or should I just stick with cloud functions? – KatM Jul 21 '21 at 15:39
  • As said in my answer: 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. Your Flutter app runs on devices from your regular users, so is **not** a trusted environment. – Frank van Puffelen Jul 21 '21 at 16:00
  • Thank you for clarifying and for your help! I kind of thought this was the case but I know nothing about Flutter. I will look into Cloud Functions as a possible solution for what I want to do and post separately if I get "stuck". Thank you again for answering so quickly :) – KatM Jul 21 '21 at 17:35