Skip to content

Commit 098b735

Browse files
charlotteliangncooke3
authored andcommitted
Remote Config Dynamic Property Wrapper (#10155)
1 parent 4f17c8b commit 098b735

File tree

19 files changed

+1181
-8
lines changed

19 files changed

+1181
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ FirebaseAuth/Tests/Sample/SwiftApiTests/Credentials.swift
99
FirebaseDatabase/Tests/Resources/GoogleService-Info.plist
1010

1111
FirebaseRemoteConfig/Tests/Sample/GoogleService-Info.plist
12+
FirebaseRemoteConfigSwift/Apps/SwiftUISample/SwiftUISample/GoogleService-Info.plist
1213

1314
# FirebaseStorage integration tests GoogleService-Info.plist
1415
FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
static NSString *const kRemoteConfigMinimumFetchIntervalKey = @"_rcn_minimum_fetch_interval";
4040
/// Timeout value for waiting on a fetch response.
4141
static NSString *const kRemoteConfigFetchTimeoutKey = @"_rcn_fetch_timeout";
42+
/// Notification when config is successfully activated
43+
const NSNotificationName FIRRemoteConfigActivateNotification =
44+
@"FIRRemoteConfigActivateNotification";
4245

4346
/// Listener for the get methods.
4447
typedef void (^FIRRemoteConfigListener)(NSString *_Nonnull, NSDictionary *_Nonnull);
@@ -277,7 +280,7 @@ - (void)fetchAndActivateWithCompletionHandler:
277280
[self fetchWithCompletionHandler:fetchCompletion];
278281
}
279282

280-
#pragma mark - apply
283+
#pragma mark - activate
281284

282285
typedef void (^FIRRemoteConfigActivateChangeCompletion)(BOOL changed, NSError *_Nullable error);
283286

@@ -314,13 +317,16 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
314317
toSource:RCNDBSourceActive
315318
forNamespace:self->_FIRNamespace];
316319
strongSelf->_settings.lastApplyTimeInterval = [[NSDate date] timeIntervalSince1970];
320+
// New config has been activated at this point
317321
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000069", @"Config activated.");
318322
[strongSelf->_configContent activatePersonalization];
319-
320323
// Update experiments only for 3p namespace
321324
NSString *namespace = [strongSelf->_FIRNamespace
322325
substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
323326
if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
327+
dispatch_async(dispatch_get_main_queue(), ^{
328+
[self notifyConfigHasActivated];
329+
});
324330
[strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
325331
if (completion) {
326332
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@@ -339,6 +345,19 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
339345
dispatch_async(_queue, applyBlock);
340346
}
341347

348+
- (void)notifyConfigHasActivated {
349+
// Need a valid google app name.
350+
if (!_appName) {
351+
return;
352+
}
353+
// The Remote Config Swift SDK will be listening for this notification so it can tell SwiftUI to
354+
// update the UI.
355+
NSDictionary *appInfoDict = @{kFIRAppNameKey : _appName};
356+
[[NSNotificationCenter defaultCenter] postNotificationName:FIRRemoteConfigActivateNotification
357+
object:self
358+
userInfo:appInfoDict];
359+
}
360+
342361
#pragma mark - helpers
343362
- (NSString *)fullyQualifiedNamespace:(NSString *)namespace {
344363
// If this is already a fully qualified namespace, return.

FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
/// The timeout to set for outgoing fetch requests.
3333
@property(nonatomic, readwrite, assign) NSTimeInterval fetchTimeout;
34-
34+
// The Google App ID of the configured FIRApp.
35+
@property(nonatomic, readwrite, copy) NSString *googleAppID;
3536
#pragma mark - Data required by config request.
3637
/// Device authentication ID required by config request.
3738
@property(nonatomic, copy) NSString *deviceAuthID;

FirebaseRemoteConfigSwift.podspec

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ app update.
3535
s.prefix_header_file = false
3636

3737
s.source_files = [
38-
'FirebaseRemoteConfigSwift/Sources/*.swift',
38+
'FirebaseRemoteConfigSwift/Sources/**/*.swift',
3939
]
4040

4141
s.dependency 'FirebaseRemoteConfig', '~> 10.0'
@@ -53,6 +53,9 @@ app update.
5353
'FirebaseRemoteConfigSwift/Tests/FakeUtils/*.swift',
5454
'FirebaseRemoteConfigSwift/Tests/ObjC/*.[hm]',
5555
]
56+
# Excludes tests that cannot be include in API tests because it requires fetch remote values from
57+
# a real console but only one test can be run without poluting other tests' remote values.
58+
swift_api.exclude_files = ['FirebaseRemoteConfigSwift/Tests/SwiftAPI/PropertyWrapperTests.swift']
5659
swift_api.resources = 'FirebaseRemoteConfigSwift/Tests/Defaults-testInfo.plist'
5760
swift_api.requires_app_host = true
5861
swift_api.pod_target_xcconfig = {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Uncomment the next line to define a global platform for your project
2+
# platform :ios, '14.0'
3+
4+
source 'https://github.com/firebase/SpecsDev.git'
5+
source 'https://github.com/firebase/SpecsStaging.git'
6+
source 'https://cdn.cocoapods.org/'
7+
8+
target 'SwiftUISample' do
9+
# Comment the next line if you don't want to use dynamic frameworks
10+
use_frameworks!
11+
pod 'FirebaseAnalytics'
12+
pod 'FirebaseCore', :path => '../../../'
13+
pod 'FirebaseCoreInternal', :path => '../../../'
14+
pod 'FirebaseCoreDiagnostics', :path => '../../../'
15+
pod 'FirebaseInstallations', :path => '../../../'
16+
pod 'FirebaseRemoteConfig', :path => '../../../'
17+
pod 'FirebaseRemoteConfigSwift', :path => '../../../'
18+
pod 'FirebaseSharedSwift', :path => '../../..'
19+
pod 'FirebaseABTesting', :path => '../../..'
20+
21+
end

0 commit comments

Comments
 (0)