Firebase iOS设置优先级不更新查询

时间:2014-10-17 00:25:46

标签: ios firebase

我在使用iOS库正确观察Firebase查询时遇到问题。只有在同一客户端上更新优先级时才会出现此问题。下面是一个测试案例,用于演示我遇到的问题。

我想观察特定优先级的子计数。 countLabel只显示优先级为#34;一个"的子项数。有一个按钮可以触发changePriority()以确定新孩子的优先级"两个"。我希望countLabel显示0(或递减到正确的数字),但它不会更新。

class ViewController: UIViewController {
    let firebaseRoot = Firebase(url: "url goes here")
    var newChild: Firebase?

    @IBOutlet weak var countLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        firebaseRoot.queryEqualToPriority("one").observeEventType(FEventType.Value, withBlock: { (snapshot: FDataSnapshot!) -> Void in
            self.countLabel.text = snapshot.childrenCount.description
        })

        newChild = firebaseRoot.childByAutoId()
        newChild?.setValue(true, andPriority: "one")
    }

    @IBAction func changePriority() {
        newChild?.setPriority("two", withCompletionBlock: { (error: NSError?, firebase: Firebase!) -> Void in
            if (error == nil) {
                NSLog("Priority updated to `two`")
            } else {
                NSLog("Error updating priority: %@", error!)
            }
        })
    }
}

重要的是,如果我使用其他客户端(或Vulcan)更改该子项的优先级,则查询观察者会正确响应,countLabel将显示正确的数字。

1 个答案:

答案 0 :(得分:2)

看起来这是Firebase iOS SDK中的一个错误。感谢您引起我们的注意!幸运的是,我们实际上正在改进我们的查询支持,并且目前有一个beta SDK可用,除了具有新功能外,还修复了这个错误。如果你想试一试,请查看http://www.firebase.com/docs/beta/queries

否则,如果您等待几周,这些功能(以及错误修复)将进入发布SDK。