【发布时间】:2020-04-26 10:40:20
【问题描述】:
看起来setDefaults: 没有正确解析和存储嵌套的 NSDictionary 对象。
这是一些简单的测试代码:
FIRRemoteConfig *remoteConfig = [FIRRemoteConfig remoteConfig];
NSDictionary *defaultValues = @{
@"stringTestKey": @"stringValue",
@"numberTestKey": @10,
@"dictionaryTestKey": @{
@"nestedKey":@"nestedValue"
}
};
NSLog(@"default dict > %@", defaultValues);
[remoteConfig setDefaults:defaultValues];
NSString *stringTest = [remoteConfig defaultValueForKey:@"stringTestKey"].stringValue;
NSNumber *numberTest = [remoteConfig defaultValueForKey:@"numberTestKey"].numberValue;
NSDictionary *dictionaryTest = [remoteConfig defaultValueForKey:@"dictionaryTestKey"].JSONValue;
NSLog(@"String value > %@", stringTest);
NSLog(@"Number value > %@", numberTest);
NSLog(@"Dictionary value > %@", dictionaryTest);
前两个NSLog 正确返回stringValue 和10,但第三个简单返回null。
是我做错了什么还是当前的 SDK 坏了?
【问题讨论】:
-
您希望它记录什么,为什么?
-
我在代码示例下方评论:第三个 NSLog 应该返回一个 NSDictionary,它是
dictionaryTestKey的值。相反,它返回(null)。 -
我也在 Firebase 文档提供的 Objective-C 演示项目中测试了相同的行为:当一个具有字典值类型的新键添加到演示中包含的 plist 时,
defaultValueForKey键返回(null)。 -
如果我正确阅读了文档,JSONValue 会将配置字段的值解析为 JSON。这意味着它可能需要一个字符串作为输入,这就是您表示 JSON 的方式。
-
如果您认为有错误,请在 GitHub 上提交错误报告。 github.com/firebase/firebase-ios-sdk
标签: ios objective-c firebase firebase-remote-config