arsenius
arsenius

Reputation: 13246

FIRRemoteConfig.activateFetched() fails

I've implemented FIRRemoteConfig and added my first value in the firebase console. However, when I try to activate the fetched values it fails and my remote value is never available.

    let remote = FIRRemoteConfig.remoteConfig()
    #if DEBUG
        let expiration: TimeInterval = 0
        remote.configSettings = FIRRemoteConfigSettings(developerModeEnabled: true)
    #else
        let expiration: TimeInterval = 24*60*60
    #endif

    var map = [String:NSObject]()
    let defaults = RemoteSettings.defaults.keys
    for key in defaults.keys {
        map[key.rawValue] = defaults[key] as? NSObject
    }
    remote.setDefaults(map) // Have confirmed that map is valid here

    remote.fetch(withExpirationDuration: expiration, completionHandler: { (status, error) in
        // status always == .success, but remote.activateFetched() always returns false.
        if status == .success && remote.activateFetched() {
            print("applied remote settings")
        } else {
            print("failed to apply remote settings: \(error)")
        }
    })

Upvotes: 3

Views: 4753

Answers (3)

Nadzeya
Nadzeya

Reputation: 651

As @Sunil Phani Manne mentioned, using the method with expiration value really works and forces remoteConfig to activate immediately.

    self.remoteConfig?.fetch(withExpirationDuration: 0.0, completionHandler: { (status, error) in
        let result = self.remoteConfig?.activateFetched()
        print(result)
    })

Upvotes: 3

Sunil Phani Manne
Sunil Phani Manne

Reputation: 432

I figured out after a lot of trial and error. The problem is with the expiration value, set the expiration value to 0 seconds to see the immediate results put into effect!

I hope this could save a lot of time for others guys!

Upvotes: 11

arsenius
arsenius

Reputation: 13246

Using remote.activateFetched() fails, but using FIRRemoteConfig.remoteConfig().activateFetched() is successful. Perhaps google wants us to use remoteConfig() every time rather than holding onto a specific instance.

Additionally, a look at the documentation mentions that this will actually fail if the fetched settings have already been applied previously.

Returns false if no Fetched Config was found, or the Fetched Config was already activated.

Upvotes: 3

Related Questions