Reputation: 970
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.
Upvotes: 8
Views: 5061
Reputation: 96
What I did was set up an XMPP server with Ejabbered in order to conduct notifications. Hope the following helps.
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
Upvotes: 0
Reputation: 970
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
Upvotes: 2
Reputation: 3112
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.
Upvotes: 0