Does Firebase RemoteConfig keep fetching?

2.4k views Asked by At

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?

1

There are 1 answers

1
Willjay On BEST ANSWER

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
    }
}