【问题标题】:Flutter firestore message notifications [closed]Flutter Firestore消息通知[关闭]
【发布时间】:2020-11-23 20:55:38
【问题描述】:

我已经使用 Cloud Firestore 实现了一个聊天应用程序。

流程是这样的:

  1. 有一个聊天集合,其中保存了两个用户 ID。并且聊天集合具有内部消息集合,所有消息都保存在其中。
  2. 两个用户可以即时互相发送消息。
  3. 此外,任何用户都可以与任何其他用户发起聊天。

我想知道什么?

我想在发送新消息时在接收方手机上发送通知。如果有人能理解这个问题。帮助将不胜感激

【问题讨论】:

    标签: firebase flutter google-cloud-firestore notifications messaging


    【解决方案1】:

    我发现this 文章可能对你有用,它非常详细,甚至包括code,基本上诀窍是使用Cloud Firebase Functions 来监听集合的任何变化,在您的特定用例中,尝试侦听onCreate 触发器,每次用户在集合上创建新消息(文档)时都会触发该触发器,有关数据库触发器的更多信息可以找到here

    那么你只需要在onCreate监听器中触发sendToDevicemethod就可以将消息推送到设备中。

    【讨论】:

      【解决方案2】:

      Firebase 云函数可用于根据您自己的业务逻辑创建和触发函数。我假设你已经配置了你的 Flutter 应用程序并将其与 firebase 连接,如果没有,以下步骤也将指导你完成。

      1. This link here will guide you on how to start with cloud functions basically what all you need to do to set up the environment.

      2. This link is a complete example which demonstrates on how to push notifications to a particular user device using the device token whenever a new document is added to a collection.

      3. This is a youtube video for the above links.

      请浏览链接并帮助自己。

      【讨论】:

        猜你喜欢
        • 2019-11-22
        • 2011-05-19
        • 2021-02-19
        • 2022-01-17
        • 2019-01-24
        • 2014-08-23
        • 2023-03-21
        • 2019-10-08
        • 2021-07-22
        相关资源
        最近更新 更多