I am using Firebase Remote Config feature in my app. I need to add a network timeout on the fetch request.
#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?()
}
How can I do?
You can have a workaround for that by using a timer:
remoteConfigTimer = Timer.scheduledTimer(withTimeInterval: 10,
repeats: false) {
timer in
self.remoteConfigTimerExpired = true
self.loadingDoneCallback()
}
Here you define your timeout as the timeInterval of your Timer, and once this timer is reached you just execute the same method you would execute if the RemoteConfig call was successful.
Note that this is only available for iOS 10 or higher.
There's a fetchTimeout
setting that you can use when you initialise FIRRemoteConfig.configSettings
.
The documentation and details are here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With