Firebase无法设置RemoteConfig默认值

3
我正在使用Firebase的RemoteConfig框架。从Firebase服务器获取数据运作良好(已经在生产中工作),但设置默认值似乎不起作用。我尝试遵循文档,但可能做错了什么。
为了测试这一点,我做了以下操作:
[self.remoteConfig setDefaults:@{@"key1": @"value1"}];

然后,在Firebase控制台中,我将参数key1设置为默认值No Value,这将向客户端发送零数据。我没有定义任何其他条件,因此这是唯一的值。根据文档,在此情况下,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

value1nil

remoteValue1.dataValue_NSZeroData

此外,当我尝试使用时

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

我收到了一个nil值(假设将nil发送给namespace参数会给我默认的名称空间)。这里我是否有什么错误?
1个回答

4

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

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

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


谢谢,我在头文件中不小心错过了FIRNamespaceGoogleMobilePlatform常量。 - Boris Talesnik
1
对于Swift开发者来说,命名空间是NamespaceGoogleMobilePlatform,在FIRRemoteConfig.h中声明。 - Ashley Mills

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接