Send push notifications when updating a Firebase Node real-time database

I created an application that uses firebase database and database storage. My application allows users to inform each other, but I'm not sure how to notify the user when they received a new message. I save all messages in a single node message. Then I save the message relationship in another node called "user-messages". How to track the "custom messages" node to warn the user that he has a new message? I am familiar with the types of observation events, etc. For example: .Value and .ChildAdded, but I'm not sure how to trigger an event to send a notification to the user.

edit: gave a little more clairity.

+7
ios swift push-notification notifications firebase
source share
3 answers

So I accidentally did not see that Firebase can use Google Cloud Messaging, which seems to be able to do what I want. For a future link, firebase set the IOS setting here: Firebase Cloud Messaging SetUp

+2
source share

As you already mentioned, you can use the child_added event to monitor whenever a new message is added to user-messages and firebase will call an event handler whenever a new child is added.

 ref.child('user-messages').on('child_added', (snapshot) => { // Read the message and send notification here }) 

You might want to update user-message , as well as after it has been processed so that you do not send repeated notifications when your application restarts.

0
source share
0
source share

All Articles