8
votes

I have created an app which uses firebase real-time database and storage. My app allows users to message each other, but I am not sure how to notify the user when they have received a new message. I store all of the messages in one node called messages. I then store the message relationships in a different node called "user-messages". How do I monitor the "user-messages" node to alert the user with a notification that they have a new message? I am familiar with observing event types and such, i.e.: .Value and .ChildAdded, but I am not sure how to trigger an event to send the user a notification.

edit: gave a little more clairity.

3
I'm not sure how that answers my question. That only allows me to send a push notification to a specific list of users.Taylor Simpson

3 Answers

2
votes

So I accidently did not see that Firebase can use Google Cloud Messaging which seems to be able to do what I want. For future reference firebase has put the IOS setup here :Firebase Cloud Messaging SetUp

0
votes

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

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

You may want to update the user-message as well after it has been handled so that you don't end up sending duplicate notifications when your app restarts.