我正在使用 Swift 在 iOS 上开始使用 RemoteConfig,并按照教程开始使用。我启用了开发者模式并通过 Firebase 控制台测试了配置值的更新。但是,更新值永远不会与本地配置值同步。
代码:
override func viewDidLoad() {
super.viewDidLoad()
syncRemoteConfig()
}
fileprivate func syncRemoteConfig() {
let remoteConfig = RemoteConfig.remoteConfig()
#if DEBUG
let settings = RemoteConfigSettings()
settings.minimumFetchInterval = 0
remoteConfig.configSettings = settings
#endif
remoteConfig.fetchAndActivate { (status, error) in
let posts = remoteConfig.configValue(forKey: "posts").jsonValue as! [[String: AnyObject]]
print(posts) // <== Always print the previous data
if let error = error {
print(error.localizedDescription)
}
//status always prints status.successUsingPreFetchedData
}
}
最佳答案
运行 pod update
至少到 Firebase 6.25.0。
它修复了 race condition bug其中minimumFetchInterval
在获取之前可能尚未应用。
关于Swift 远程配置 : fetchAndActivate does not update local config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61835105/