ios - Firebase 无法设置 RemoteConfig 默认值

标签 ios firebase firebase-remote-config

我正在使用 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

value1nil

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/

相关文章:

ios - 在 Firebase block 外使用变量

javascript - 10 小时后删除 Firebase 子级

swift - Firebase Remote Config/Analytics setUserProperty 条件不执行任何操作

ios - Firebase 远程配置错误 8003,Unity,iOS

ios - 如何将 iOS UIAutomation 测试的输出转换为 Jenkins 的 JUnit 样式输出?

ios - IOS 中的 splashboardd SIGABRT 崩溃——这意味着什么?

android - iOS中Webview Flutter字体太小

ios - View 转换后如何修复不均匀的边框宽度?

postgresql - Firebase:如何从外部数据库读取?

ios - Swift/iOS - Firebase 远程配置获取值永远不会完成