Swift iOS Firebase- 如果在观察节点时出现问题 withCancel: 事件只触发一次或每次循环 children?

Swift iOS Firebase- If something goes wrong when observing a node does withCancel: event trigger only once or everytime it loops through the children?

我有一个 3 children 的裁判。我想使用 .childAdded.value 来观察它。有一个 withCancel: 事件 运行 如果出现问题。因为我一直在测试,所以我还没有 withCancel: 运行 所以这就是我问这个问题的原因。

如果确实出现问题并且 withCancel: 运行 会 运行 每次循环发生还是仅在查询的初始时间发生一次?

例如。如果 .childAdded.value 抢到第一个 child 并且成功,那么当它去抢第二个 child 时就会出现问题 withCancel: 运行,但随后它会尝试第三次 child,这可能会成功,也可能会被取消。这意味着我肯定有第一个child,我肯定没有第二个,但我可能有也可能没有第三个

一旦建立连接并且关闭的快照是 运行 withCancel: 将永远没有机会开火,我保证得到所有 3 children ?这意味着一旦观察者开始,如果它到达第一个 child 我保证会得到第二个和第三个,因为 withCancel: 一旦开始观察就不会触发。相反,在它到达第一个 child 之前,如果 withCancel: 触发,那么我将无法获得第二个和第三个,我什么也得不到。

            // or .value
ref?.observe( .childAdded, with: { [weak self](snapshot) in

         // do something with each snapshot

    }, withCancel: { [weak self](error) in

        // do something based on wether this will fire only once or can fire multiple times
        // for example if only once and I won't get anything then reload the tableView
        // if in can run multiple times then don't reload the tableView until it's finished. I have to add a limit to the query
})

documentation 声明当您不再具有观察引用的权限时,withCancel 块将触发。我不确定你说的 "if something goes wrong" 是什么意思,但这不是 withCancel 区块的事。