当用户喜欢您的 post Instagram 时发送推送通知

Sending push notifications when a user likes your post like Instagram

我正在练习 Swift 编程,尝试通过构建 Instagram 来获得乐趣。我正在使用 firebase 作为我的数据库。我能够设置 activity 页面,它显示用户在您的 post.

上有 liked/commented

现在我想知道发生这种情况时如何发送推送通知?我尝试使用 FirebaseMessaging,但我真正能做的就是直接从 firebase 发送消息。

如何向特定用户发送有人喜欢他们 post 的推送通知?

您可以尝试使用 Firebase 函数。以下是基本概念:

  1. 要接收通知,用户必须使用 subscribeToTopic(String topic)
  2. 订阅 "topic"
  3. 每当从该主题创建 post 时,您就可以使用 firebase 消息传递向该主题发送消息
  4. 为此,您需要为 firebase 托管一个函数。该函数监听新的 posts 在您使用的任何节点上被 posted
  5. 每次向该节点写入新的 post 时,它都会发送消息

这是示例 Firebase Functions Example 的 link(要托管的函数是 sendNotificationToLocation)。

检查如何处理 subscribing/unsubscribing 和处理 message/notification Firebase messaging

  1. 首先进行 Firebase 云消息传递的所有配置。
  2. 然后获取您要向其发送推送通知的用户的 firebase 注册令牌。
  3. follow this link详细解释