ios - 子集合的 Firestore 监听器

标签 ios swift firebase google-cloud-firestore

我的 Firestore 设置如下:

Channels [collection] ----> channelID ---> Messages [collection] ---> 消息ID

如何将 snapshotListener 添加到子集合“消息”?

  Firestore.firestore().collection("Channels").document().collection("Messages").addSnapshotListener { (querySnapshot, error) in
        guard let snapshot = querySnapshot else {
            print("Error listening for channel updates: \(error?.localizedDescription ?? "No error")")
            return
        }

        snapshot.documentChanges.forEach { change in 
           print(change)
        }
    }

这对我不起作用

最佳答案

您不能让单个监听器从未知数量的子集合中接收更新。集合中的监听器没有“通配符”运算符。您必须选择一个特定的集合或查询并为其附加一个监听器。

关于ios - 子集合的 Firestore 监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53227376/

相关文章:

iphone - 从(子) View 返回时更改 View 标题

ios - pushViewController 不工作

ios - 为什么ios系统的声音在模拟器中播放不了?

ios - ScrollView 内的 TextView 粘在键盘上

ios - swift - 我可以比较 Any.Type 吗?

ios - 无法看到以编程方式快速添加到 UITabBar 的 Controller

ios - 添加的图像在表格 View 中显示不正确

ios - 将Firebase Admin SDK添加到Swift

android - 火力地堡崩溃 : Failed to initialize crash reporting

ios - 如何将数据添加到 Firebase?