我正在使用 Firebase 的 RemoteConfig
框架。
从 Firebase 服务器获取数据工作正常(已经在生产中工作),但设置默认值似乎不起作用。我试图坚持文档,但也许我做错了什么。
为了测试这一点,我做了以下事情:
[self.remoteConfig setDefaults:@{@"key1": @"value1"}];
然后,在 Firebase 控制台
中,我将参数 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);
}
remoteValue1
不是nil
。
value1
为 nil
。
remoteValue1.dataValue
是 _NSZeroData
。
此外,当我尝试使用
[self.remoteConfig defaultValueForKey:@"key1" namespace:nil]
我得到一个 nil
值(假设将 nil
作为 namespace
参数发送给我默认的命名空间默认值)。
我是不是做错了什么?
最佳答案
configValueForKey:
方法首先检查从 Firebase 服务器获取的结果,如果结果存在,则返回远程结果而不是默认值。
所以key1的值应该是你在console中设置的,也就是nil
(没有值)。
当您调用 defaultVaueForKey:namespace:
时,您应该始终使用默认命名空间 FIRNamespaceGoogleMobilePlatform
。使用 nil
将不会返回任何有效的配置结果。
关于ios - Firebase 无法设置 RemoteConfig 默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40783521/