Skip to content

Commit a23a476

Browse files
authored
Support array / dictionary values in Remote Config defaults (#8307)
1 parent d01b2b1 commit a23a476

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

FirebaseRemoteConfig/Sources/RCNConfigContent.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ - (void)copyFromDictionary:(NSDictionary *)fromDict
201201
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
202202
NSString *strValue = [dateFormatter stringFromDate:(NSDate *)value];
203203
valueData = [(NSString *)strValue dataUsingEncoding:NSUTF8StringEncoding];
204+
} else if ([value isKindOfClass:[NSArray class]]) {
205+
NSError *error;
206+
valueData = [NSJSONSerialization dataWithJSONObject:value options:0 error:&error];
207+
if (error) {
208+
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000076", @"Invalid array value for key '%@'",
209+
key);
210+
}
211+
} else if ([value isKindOfClass:[NSDictionary class]]) {
212+
NSError *error;
213+
valueData = [NSJSONSerialization dataWithJSONObject:value options:0 error:&error];
214+
if (error) {
215+
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000077",
216+
@"Invalid dictionary value for key '%@'", key);
217+
}
204218
} else {
205219
continue;
206220
}

FirebaseRemoteConfig/Tests/Unit/Defaults-testInfo.plist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,20 @@
1616
<string>To setup default config.</string>
1717
<key>format</key>
1818
<string>key to value.</string>
19+
<key>arrayValue</key>
20+
<array>
21+
<string>foo</string>
22+
<string>bar</string>
23+
<string>baz</string>
24+
</array>
25+
<key>dictValue</key>
26+
<dict>
27+
<key>foo</key>
28+
<string>foo</string>
29+
<key>bar</key>
30+
<string>bar</string>
31+
<key>baz</key>
32+
<string>baz</string>
33+
</dict>
1934
</dict>
2035
</plist>

FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,6 +1289,10 @@ - (void)testSetDefaultsFromPlist {
12891289
XCTAssertEqualObjects(_configInstances[i][@"FileInfo"].stringValue,
12901290
@"To setup default config.");
12911291
XCTAssertEqualObjects(_configInstances[i][@"format"].stringValue, @"key to value.");
1292+
XCTAssertEqualObjects(_configInstances[i][@"arrayValue"].JSONValue,
1293+
((id) @[ @"foo", @"bar", @"baz" ]));
1294+
XCTAssertEqualObjects(_configInstances[i][@"dictValue"].JSONValue,
1295+
((id) @{@"foo" : @"foo", @"bar" : @"bar", @"baz" : @"baz"}));
12921296

12931297
// If given a wrong file name, the default will not be set and kept as previous results.
12941298
[_configInstances[i] setDefaultsFromPlistFileName:@""];

0 commit comments

Comments
 (0)