2016-11-24 98 views
1

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

为了验证这一点,我做了以下内容:

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

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

取代码:

[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); 
} 

remoteValue1nil

value1nil

remoteValue1.dataValue_NSZeroData

而且,当我尝试使用

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

我得到一个nil值(假设发送nil到作为namespace参数会给我默认命名空间的默认值)。

我在这里做错了什么?

回答

1

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

所以key1值应该是你在控制台中设置的值,它是零(无值)。

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

+0

谢谢,我不知何故错过了头文件中的FIRNamespaceGoogleMobilePlatform常量。 –