我正在使用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
。nil
是remoteValue1.dataValue
。_NSZeroData
是nil
。而且,当我尝试使用
[self.remoteConfig defaultValueForKey:@"key1" namespace:nil]
我得到一个
nil
值(假设将namespace
发送为ojit_code参数将为我提供默认的名称空间默认值)。我在这里做错什么了吗?
最佳答案
configValueForKey:
方法首先检查从Firebase服务器获取的结果,如果结果存在,则返回远程结果而不是默认值。
因此key1值应该是您在控制台中设置的值,即nil
(无值)。
调用defaultVaueForKey:namespace:
时,应始终使用默认名称空间FIRNamespaceGoogleMobilePlatform
。使用nil
不会返回任何有效的配置结果。