我正在使用Firebase的RemoteConfig框架。
从Firebase服务器获取数据工作正常(已经在生产环境中工作),但是设置默认值似乎无效。我试图坚持使用文档,但是也许我做错了什么。

为了对此进行测试,我做了以下工作:

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

然后,在Firebase Console中,我将参数key1设置为具有默认No Value,该默认RemoteConfig向客户端发送零数据。我没有定义任何其他条件,因此这是将发送的唯一值。根据documentation,在这种情况下remoteValue1对象应选择默认值。

获取代码:
[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);
}
nil不是value1
nilremoteValue1.dataValue
_NSZeroDatanil

而且,当我尝试使用
[self.remoteConfig defaultValueForKey:@"key1" namespace:nil]

我得到一个nil值(假设将namespace发送为ojit_code参数将为我提供默认的名称空间默认值)。

我在这里做错什么了吗?

最佳答案

configValueForKey:方法首先检查从Firebase服务器获取的结果,如果结果存在,则返回远程结果而不是默认值。

因此key1值应该是您在控制台中设置的值,即nil(无值)。

调用defaultVaueForKey:namespace:时,应始终使用默认名称空间FIRNamespaceGoogleMobilePlatform。使用nil不会返回任何有效的配置结果。

10-06 07:37
查看更多