【发布时间】:2018-01-14 06:54:14
【问题描述】:
一旦启用 Firebase 持久性,我就遇到了一些问题,我有机会阅读了其余发布的问题并查看了答案,但仍然没有按预期工作。
我已启用 firebase 持久性并使用按值观察来获取特定节点的最新更新。它不仅会不断获取旧值,而且一旦我离开特定的视图控制器并返回到该视图控制器,值就会更改为最近的值。
在第一次调用时是否有适当的方法来请求最近的值?
我试过的代码:
// MARK: Bill authenticate function
func authenticateBill(completion: @escaping (_ bill: Double?, _ billStatus: BillError?) -> Void) {
// Observe incase bill details exist for current case
let billRef = self.ref.child("bills").child((caseRef?.getCaseId())!)
billRef.observe(FIRDataEventType.value, with: { (billSnapshot) in
if !billSnapshot.exists() {
completion(nil, BillError.unavailable)
return
}
if let billDictionary = billSnapshot.value as? [String: AnyObject] {
let cost = billDictionary["cost"] as! Double
print("Cost: ", cost)
completion(cost, nil)
}
})
}
【问题讨论】:
标签: ios swift firebase swift3 firebase-realtime-database