Firebase Remote Config setDefaults: 不存储 NSDictionary



看起来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正确返回stringValue10但是第三个只是返回null

我做错了什么还是当前的SDK坏了?

不确定您是否找到了解决方案,但是我现在遇到了同样的问题,经过一段时间的挖掘,事实证明您需要将其保存为String类型而不是Dictionary,我使用plist文件获取默认值,只需添加新键dictionaryTestKey,并将类型设置为String,将值设置为类似

{   “url”: "https://google.com”,   "nestedKey": "nestedValue" } 然后使用setDefaults保存默认值, 当您需要检索它时,请使用

let data = RemoteConfig.remoteConfig().configValue(forKey: "dictionaryTestKey").dataValue let result = try? JSONDecoder().decode(YourDecodableStruct.self, from: data)

您将获得所需的所有信息。

最新更新