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.
我创建了一个使用firebase实时数据库和存储的应用程序。我的应用程序允许用户互相发送消息,但我不确定如何在收到新消息时通知用户。我将所有消息存储在一个名为messages的节点中。然后,我将消息关系存储在名为“user-messages”的不同节点中。如何监控“用户消息”节点以通知用户有新消息的通知?我熟悉观察事件类型等,即:.Value和.ChildAdded,但我不知道如何触发事件来向用户发送通知。
edit: gave a little more clairity.
编辑:给了更多的肯定。
3 个解决方案
#1
2
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
所以我意外地没有看到Firebase可以使用Google Cloud Messaging,它似乎可以做我想要的。为了将来参考,firebase已将IOS设置放在此处:Firebase Cloud Messaging SetUp
#2
0
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.
就像你提到的那样,你可以使用child_added事件监视每当新消息被添加到用户消息时,firebase会在添加新子节点时调用你的事件处理程序。
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.
您可能还希望在处理完用户消息后更新用户消息,以便在应用重新启动时不会发送重复的通知。
#3
0
What I did was set up an XMPP server with Ejabbered in order to conduct notifications. Hope the following helps.
我所做的是设置一个带有Ejabbered的XMPP服务器以进行通知。希望以下有所帮助。
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
https://firebase.google.com/docs/cloud-messaging/server#implementing-the-xmpp-connection-server-protocol
#1
2
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
所以我意外地没有看到Firebase可以使用Google Cloud Messaging,它似乎可以做我想要的。为了将来参考,firebase已将IOS设置放在此处:Firebase Cloud Messaging SetUp
#2
0
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.
就像你提到的那样,你可以使用child_added事件监视每当新消息被添加到用户消息时,firebase会在添加新子节点时调用你的事件处理程序。
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.
您可能还希望在处理完用户消息后更新用户消息,以便在应用重新启动时不会发送重复的通知。
#3
0
What I did was set up an XMPP server with Ejabbered in order to conduct notifications. Hope the following helps.
我所做的是设置一个带有Ejabbered的XMPP服务器以进行通知。希望以下有所帮助。
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
https://firebase.google.com/docs/cloud-messaging/xmpp-server-ref
https://firebase.google.com/docs/cloud-messaging/server#implementing-the-xmpp-connection-server-protocol