0
我正在正確觀察iOS庫中的Firebase查詢時遇到問題。只有在更新同一客戶端上的優先級時纔會出現此問題。下面是一個測試案例來演示我遇到的問題。Firebase iOS設置優先級沒有更新查詢
我想觀察特定優先級的孩子數。 countLabel
只顯示優先級爲「1」的孩子的數量。有一個按鈕觸發changePriority()
使新孩子的優先級爲「2」。我期望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!)
}
})
}
}
重要的是,如果我改變使用其他客戶端(或火神)那個孩子的優先級,查詢觀察者正確響應,並countLabel
會顯示正確的號碼。
您尚未在此處聲明任何錯誤處理程序或回調以查看操作是否成功。客戶端操作似乎很可能無法更新優先級。 – Kato 2014-10-27 17:25:09
@Kato,我一直在使用[Vulcan](https://github.com/firebase/vulcan)來驗證客戶端代碼是否正確地更新了服務器。此外,根據[Firebase活動保證](https://www.firebase.com/docs/ios/guide/retrieving-data.html#section-guarantees),即使服務器已經啓動,聽衆似乎也應該啓動尚未更新。我認爲這可能是iOS客戶端的一個漏洞,並且已經提交給Firebase支持。 – Brad 2014-10-27 18:03:52
@Kato我更新了示例代碼,以便在更新優先級時使用完成塊。完成塊被調用時沒有錯誤,並且我仍然遇到同樣的問題。 – Brad 2014-10-27 22:46:23