我正在我的应用中使用 Firebase 远程配置功能。 我需要在获取请求上添加网络超时。
#if DEBUG
let expirationDuration: TimeInterval = 0
RemoteConfig.remoteConfig().configSettings = RemoteConfigSettings(developerModeEnabled: true)
#else
let expirationDuration: TimeInterval = 3600
#endif
RemoteConfig.remoteConfig().fetch(withExpirationDuration: expirationDuration) {
[weak self] (status, error) in
guard error == nil else {
print ("Uh-oh. Got an error fetching remote values \(String(describing: error))")
return
}
RemoteConfig.remoteConfig().activateFetched()
self?.fetchComplete = true
self?.loadingDoneCallback?()
}
我该怎么办?
最佳答案
您可以使用计时器解决此问题:
remoteConfigTimer = Timer.scheduledTimer(withTimeInterval: 10,
repeats: false) {
timer in
self.remoteConfigTimerExpired = true
self.loadingDoneCallback()
}
在这里,您将超时定义为定时器的时间间隔,一旦达到此定时器,您只需执行与 RemoteConfig 调用成功时执行的方法相同的方法。
请注意,这仅适用于 iOS 10 或更高版本。
关于ios - 如何在 Firebase RemoteConfig 获取请求上添加超时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50744598/