【问题标题】:Firebase can't set RemoteConfig defaultsFirebase 无法设置 RemoteConfig 默认值
【发布时间】:2018-08-31 20:54:19
【问题描述】:

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

为了测试这一点,我做了以下操作:

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

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

获取代码:

[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 参数发送给我默认的命名空间默认值)。

我在这里做错了吗?

【问题讨论】:

    标签: ios firebase firebase-remote-config


    【解决方案1】:

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

    所以key1的值应该是你在控制台设置的,也就是nil(没有值)。

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

    【讨论】:

    • 谢谢,我不知何故错过了头文件中的FIRNamespaceGoogleMobilePlatform const。
    • 对于 Swift 开发人员 - 命名空间是 NamespaceGoogleMobilePlatform,在 FIRRemoteConfig.h 中声明
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 1970-01-01
    • 2013-01-29
    • 2020-05-19
    • 1970-01-01
    • 2023-04-01
    相关资源
    最近更新 更多