ios - Swift/iOS - Firebase 远程配置获取值永远不会完成
问题描述
下面是一个实现从 Firebase 控制台获取远程配置值的类,但是当调用获取云值时,完成块永远不会执行(即,如果我在完成块中中断,Xcode 永远不会中断)。现在所有文档似乎都已过时,我看不出我做错了什么。
@objc class RemoteConfigValues: NSObject {
@objc static let sharedInstance = RemoteConfigValues()
private override init() {
super.init()
let settings = RemoteConfigSettings()
//WARNING THIS IS FOR DEBUG ONLY
settings.minimumFetchInterval = 0
RemoteConfig.remoteConfig().configSettings = settings
loadDefaultValues()
fetchCloudValuesWith(fetchInterval: 0.0)
}
func loadDefaultValues() {
let appDefaults: [String: Any?] = [
RemoteConfigKeys.senseAdType.rawValue: String("A"),
RemoteConfigKeys.sensePromotionButton.rawValue: String("BUY NOW")
]
RemoteConfig.remoteConfig().setDefaults(appDefaults as? [String: NSObject])
}
func getInstanceIDToken() {
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instance ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}
}
func fetchCloudValues() {
RemoteConfig.remoteConfig().fetchAndActivate { (status, error) in
if let error = error {
print("Uh-oh. Got an error fetching remote values \(error)")
return
}
print("Retrieved values from the cloud!")
}
}
func fetchCloudValuesWith(fetchInterval: Double) {
RemoteConfig.remoteConfig().fetch(withExpirationDuration: fetchInterval) { status, error in
if let error = error {
print("Uh-oh. Got an error fetching remote values \(error)")
return
}
RemoteConfig.remoteConfig().activate { (error) in
print("Uh-oh. Got an error fetching remote values \(error?.localizedDescription ?? "")")
}
print("Retrieved values from the cloud!")
}
}
}
以下是打印到 Firebase/RemoteConfig 控制台的日志
2020-06-11 10:16:20.061816+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig][I-RCN000062] Loading database at path /Users/dominicbryan/Library/Developer/CoreSimulator/Devices/481BF064-0BC7-404E-836F-A0AB58FD8900/data/Containers/Data/Application/77B9DD80-FFF4-4354-8B30-23E39C794861/Library/Application Support/Google/RemoteConfig/RemoteConfig.sqlite3
2020-06-11 10:16:20.064711+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig]2020-06-11 10:16:20.065426+0100 MyApp[67337:10404579] <NSProgress: 0x600000f5c5a0> : Parent: 0x0 (portion: 0) / Fraction completed: 1.0000 / Completed: 2203 of 2203
2020-06-11 10:16:20.066622+0100 MyApp[67337:10404626] 6.12.0 - [Firebase/RemoteConfig][I-RCN000039] Starting requesting token.
2020-06-11 10:16:21.164733+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000022] Success to get iid : fqcuK-XSZsU.
2020-06-11 10:16:21.166088+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000024] Success to get device authentication ID: 5**************7, security token: 7***************8.
2020-06-11 10:16:21.166737+0100 MyApp[67337:10404579] 6.12.0 - [Firebase/RemoteConfig][I-RCN000060] Fetch with user properties completed.
解决方案
使用 yourfunc fetchCloudValuesWith(fetchInterval: Double)
而不是 using fetchAndActivate
:
remoteConfig.fetch(withExpirationDuration: 0) { [weak self] (status, error) in
//Do your stuffs
}
推荐阅读
- javascript - JavaScript 中的变量超过 1 个 URL
- r - R中具有空间自相关的GAMM
- c# - SqlException Timeout 过期进入 Dot net core 2.2
- python - 如何从 Python 打开 Visual Studio 代码?
- javascript - 单击按钮清除选择框
- sql-server - 如何将可执行的sql任务结果存储在excel文件ssis中
- c# - 在 VS2017 中更改以下 Resharper 项目的颜色
- wildfly - Wildfly 错误:错误 MEM 发送 ENABLE-APP
- c# - 如何使文本框的宽度像 xaml 中的按钮一样动态变化
- c++ - 如何找到通过公式计算的非常大的数字的最后一位?