ios - 添加 child 时,如何使用 Swift 和 Firebase 向每台设备发送通知?

标签 ios swift firebase push-notification firebase-realtime-database

我有一个功能齐全的应用程序,它使用 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:

  1. Waits for changes to a particular database location for write events.
  2. Fires when a write event occurs and performs its tasks (see What can I do with Cloud Functions? for examples of use cases).
  3. 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.

Image

  1. The function triggers on writes to the Realtime Database path where followers are stored.
  2. The function composes a message to send via FCM.
  3. 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/

相关文章:

ios - 如何在 Swift 中获取 NSMutableArray 中元素的索引?

firebase - 使用Firestore快照中的StreamController的StreamBuilder

node.js - 使用 Spark(免费)Firebase 计划通过 Cloud Functions for Firebase 导出 Excel

iphone - 核心数据应用程序崩溃, "EXC_BAD_ACCESS"& NSZombie

ios - 没有获取用于在 UITableViewCell 中点击 UISwitch 的 indexPath

ios - 聚类谷歌地图标记并放大聚类

android - 如何使用两个子值在 Firebase 中进行搜索?

iOS:智能刷新注释

ios - 我怎样才能看到 UIImageView 中的图像?

swift - ImagePickerController 在设备和模拟器上返回 "image format with an unknown type"