我有一个功能齐全的应用程序,它使用 Firebase 作为后端。我希望能够让用户在该用户 ID 下将 child 添加到我的 Firebase 数据库时收到通知。
我到处找,但我能找到的只是 的链接。 OneSignal 或者人们告诉我“制作自定义服务器”,就好像它可以通过魔法完成一样。我该如何做一个服务器?什么语言?我可以用 OneSignal 做什么?有人可以逐步指导我,而不告诉我简单地制作自定义服务器。
最佳答案
我相信Cloud Functions for Firebase正是您正在寻找的。具体来说,Realtime Database Triggers :
The Realtime Database supports the
onWrite()
event, which triggers anytime data is created, destroyed, or changed in a specified database location.In a typical lifecycle, a Firebase Realtime Database function does the following:
- Waits for changes to a particular database location for write events.
- Fires when a write event occurs and performs its tasks (see What can I do with Cloud Functions? for examples of use cases).
- Receives an event data object that contains two snapshots of the data stored at the specified path: one with the original data prior to the change, and one with the new data.
并通过What can I do with Cloud Functions? , 有 Notifying users :
Notify users when something interesting happens
Developers can use Cloud Functions to keep users engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another's activities in the app. In such an app, a function triggered by Realtime Database writes to store new followers could create Firebase Cloud Messaging (FCM) notifications to let the appropriate users know that they have gained new followers.
- The function triggers on writes to the Realtime Database path where followers are stored.
- The function composes a message to send via FCM.
- FCM sends the notification message to the user's device.
To review working code, see Send FCM notifications.
Other interesting notification use cases
- Send confirmation emails to users subscribing/unsubscribing to a newsletter.
- Send a welcome email when a user completes signup.
- Send an SMS confirmation when a user creates a new account.
关于ios - 添加 child 时,如何使用 Swift 和 Firebase 向每台设备发送通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44394335/