Search code examples
iosfirebasefirebase-remote-config

Firebase can't set RemoteConfig defaults


I'm using the RemoteConfig framework of Firebase. Fetching data from the Firebase server works fine (already working in production), but setting defaults doesn't seem to work. I tried to stick to the documentation, but maybe I'm doing something wrong.

To test this I did the following:

[self.remoteConfig setDefaults:@{@"key1": @"value1"}];

Then, in the Firebase Console I set parameter key1 to have the default No Value that sends zero data to the client. I didn't define any other conditions, so this is the only value that will be sent. According to the documentation, the RemoteConfig object should pick the defaults in this case.

Fetching code:

[self.remoteConfig fetchWithExpirationDuration:self.configurationExpirationDuration
                           completionHandler:^(FIRRemoteConfigFetchStatus status,
                                               NSError * _Nullable error) {
  if (status == FIRRemoteConfigFetchStatusSuccess) {
    [self.remoteConfig activateFetched];

    FIRRemoteConfigValue *remoteValue1 = [self.remoteConfig configValueForKey:@"key1"];
    NSString *value1 = remoteValue1.stringValue;

    // Logic comes here

  } else {
    LogError(@"Error fetching remote configuration from Firebase: %@", error);
}

remoteValue1 is not nil.

value1 is nil.

remoteValue1.dataValue is _NSZeroData.

Moreover, when I try to use

[self.remoteConfig defaultValueForKey:@"key1" namespace:nil]

I get a nil value (assuming that sending nil to as the namespace parameter will give me the default namespace defaults).

Am I doing something wrong here?


Solution

  • configValueForKey: method firstly checks fetching results from Firebase server, if the results exist, it returns the remote results instead of defaults.

    So key1 value should be what you set in console, which is nil (no value).

    When you call defaultVaueForKey:namespace: you should always use default namespace FIRNamespaceGoogleMobilePlatform. Using nil will not return any valid config results.