gpt4 book ai didi

ios - ObserveSingleEvent 返回旧数据

转载 作者:搜寻专家 更新时间:2023-10-31 19:32:38 27 4
gpt4 key购买 nike

我想在应用启动时获取所需的应用版本号。但是我找不到正确的 key 。

我要获取此代码。我使用 observe single event 因为我使用这种方法来检查所需的应用程序版本号。此方法仅在应用程序开始执行检查时触发。

func getVersion(completionHandler: @escaping (Result<Any?>) -> ()) {

let ref: DatabaseReference! = Database.database().reference().child("version").child("IOS")

ref?.observeSingleEvent(of: .value , with: { snapshot in

if snapshot.exists() {
let recent = snapshot.value as! NSDictionary
print(recent)
}
})
}

但它返回的是旧结果?我在我的 Appdelegate 中启用了 isPersistenceEnabled

这是数据库结构:

enter image description here

我在使用 Database.database().reference().child("version").child("IOS") 时没有得到任何结果。当我使用它时,snapshot.exists 是错误的。

我之前拥有的是:- 版本 | iOS - 1.0

当我使用 Database.database().reference().child("version") 时,我得到了结果,即 {iOS => 1.0}。我不明白,因为它是我的旧结构。

最佳答案

The Firebase Realtime Database synchronizes and stores a local copy of the data for active listeners. In addition, you can keep specific locations in sync.

let scoresRef = Database.database().reference(withPath: "scores")
scoresRef.keepSynced(true)

The Firebase Realtime Database client automatically downloads the data at these locations and keeps it in sync even if the reference has no active listeners. You can turn synchronization back off with the following line of code.

scoresRef.keepSynced(false)

还没有真正尝试过,但应该可以。

关于ios - ObserveSingleEvent 返回旧数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45374663/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com