2014-10-17 30 views
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會顯示正確的號碼。

+0

您尚未在此處聲明任何錯誤處理程序或回調以查看操作是否成功。客戶端操作似乎很可能無法更新優先級。 – Kato 2014-10-27 17:25:09

+0

@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

+0

@Kato我更新了示例代碼,以便在更新優先級時使用完成塊。完成塊被調用時沒有錯誤,並且我仍然遇到同樣的問題。 – Brad 2014-10-27 22:46:23

回答

2

看起來這是Firebase iOS SDK中的一個錯誤。感謝您將它引入我們的注意!幸運的是,我們實際上正在修改我們的查詢支持,並且目前有一個beta SDK,除了具有新功能外,它還修復了這個錯誤。如果你想給它一個鏡頭,退房http://www.firebase.com/docs/beta/queries

否則,如果你等了幾個星期,這些功能(和錯誤修復)將使它進入發佈SDKs。