Reputation: 44310
I have the following code that loads in the initial ViewController viewDidLoad. It works fine initially. But shouldn't it look for changes every 10 seconds?
When I make an update to a config value in Firebase and publish, I don't see this come through in the app. I am running in debug mode so throttling isn't an issue.
If I restart the app, I see the new value. Since the interval is set to 10 seconds, shouldn't I see the update while the app is running?
let rc = FIRRemoteConfig.remoteConfig()
let interval: TimeInterval = 10
FIRRemoteConfig.remoteConfig().fetch(withExpirationDuration: interval) {
(status, error) in
guard error == nil else {
//handle error here
return
}
FIRRemoteConfig.remoteConfig().activateFetched()
let test = rc["key1"].stringValue //this runs only once
}
Any ideas why this isn't update?
Upvotes: 0
Views: 2527
Reputation: 6459
You should use scheduledTimer
instead.
/// Fetches Remote Config data and sets a duration that specifies how long config data lasts.
/// Call activateFetched to make fetched data available to your app.
/// @param expirationDuration Duration that defines how long fetched config data is available, in
/// seconds. When the config data expires, a new fetch is required.
/// @param completionHandler Fetch operation callback.
open func fetch(withExpirationDuration expirationDuration: TimeInterval, completionHandler: FirebaseRemoteConfig.FIRRemoteConfigFetchCompletion? = nil)
fetch(withExpirationDuration: interval)
is to fetch data with a timeout, that is your interval.
let interval: TimeInterval = 10
Timer.scheduledTimer(timeInterval: interval,
target: self,
selector: #selector(updateConfig),
userInfo: nil,
repeats: true)
func updateConfig() {
let rc = FIRRemoteConfig.remoteConfig()
FIRRemoteConfig.remoteConfig().fetch { (status, error) in
guard error == nil else {
//handle error here
return
}
FIRRemoteConfig.remoteConfig().activateFetched()
let test = rc["key1"].stringValue //this runs only once
}
}
Upvotes: 1