0

I am running RemoteConfig fetch on a project as following to try fetch a test configuration parameter that I set to true on the server.

I have also a default configuration plist file on the app bundle.

After the fetch succeeds I call activateFetched but it seems to get the value that I have got in the default plist file which is set to false.

Any idea why?

Here is the default plist file:

enter image description here

Here is the code:

func fetchConfig() {
    var expirationDuration = 3600

    if remoteConfig.configSettings.isDeveloperModeEnabled {
        expirationDuration = 0
    }
    remoteConfig.fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (status, error) -> Void in
        if status == .success {
            print("Config fetched!")
            self.remoteConfig.activateFetched() // ?? I thought that this would override the default plist file but it does not seem to do so
            self.doSomething()
        } else {
            print("Config not fetched")
            print("Error \(error!.localizedDescription)")
        }
   }

func doSomething() {
    let status = remoteConfig.lastFetchStatus
    print(status)  // <-- adding a breakpoint here this is says SUCCESS 
    print("last fetched at: ", remoteConfig.lastFetchTime ?? "no-value") // <--- it gives me the correct time 
    let remoteParamValue = remoteConfig[testParameterConfigKey].boolValue

    if remoteParamValue {
        print("true") 
    } else{
        print("false")  // <--- it always goes here even if the test_parameter in the remote console is set to true
    }
}

Here is how I call the above:

override func viewDidLoad() {
    super.viewDidLoad()
    remoteConfig = RemoteConfig.remoteConfig()
    let remoteConfigSettings = RemoteConfigSettings(developerModeEnabled: true)
    remoteConfig.configSettings = remoteConfigSettings!
    remoteConfig.setDefaults(fromPlist: "RemoteConfigDefaults")
    fetchConfig()
}
mm24
  • 8,150
  • 11
  • 65
  • 159

2 Answers2

0

It looks to me like you're doing everything correctly. I would do two things:

  1. Watch for misspellings -- if you've set the name of the key incorrectly in the Firebase console or your testParameterConfigKey, that will mess you up (and most likely give you a false value)

  2. Don't start by testing with a boolean. If there's some mistake where you are accidentally using the wrong key or not loading up the plist file or anything like that, that will generally manifest itself by giving you a "false" value in your code. Then you have no way of knowing if you're actually getting the default value, or if you're getting a null value that's being interpreted as false. Instead, start with a string. Give it a default value of "Hello" and then try to change it in the console to "Goodbye". That should at least help you eliminate issues with your setup.

Todd Kerpelman
  • 13,951
  • 2
  • 35
  • 38
0

Did you forget to click on "Release changes" button on the top right in Firebase Console? You not only need to save a changed setting - you also need to publish them.

ThorstenC
  • 1,101
  • 10
  • 21