Skip to content

Commit

Permalink
Merge e8e11a7 into a97a5be
Browse files Browse the repository at this point in the history
  • Loading branch information
charlotteliang authored Sep 22, 2022
2 parents a97a5be + e8e11a7 commit 9da2d37
Show file tree
Hide file tree
Showing 19 changed files with 1,181 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ FirebaseAuth/Tests/Sample/SwiftApiTests/Credentials.swift
FirebaseDatabase/Tests/Resources/GoogleService-Info.plist

FirebaseRemoteConfig/Tests/Sample/GoogleService-Info.plist
FirebaseRemoteConfigSwift/Apps/SwiftUISample/SwiftUISample/GoogleService-Info.plist

# FirebaseStorage integration tests GoogleService-Info.plist
FirebaseStorage/Tests/Integration/Resources/GoogleService-Info.plist
Expand Down
23 changes: 21 additions & 2 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
static NSString *const kRemoteConfigMinimumFetchIntervalKey = @"_rcn_minimum_fetch_interval";
/// Timeout value for waiting on a fetch response.
static NSString *const kRemoteConfigFetchTimeoutKey = @"_rcn_fetch_timeout";
/// Notification when config is successfully activated
const NSNotificationName FIRRemoteConfigActivateNotification =
@"FIRRemoteConfigActivateNotification";

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

#pragma mark - apply
#pragma mark - activate

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

Expand Down Expand Up @@ -314,13 +317,16 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
toSource:RCNDBSourceActive
forNamespace:self->_FIRNamespace];
strongSelf->_settings.lastApplyTimeInterval = [[NSDate date] timeIntervalSince1970];
// New config has been activated at this point
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000069", @"Config activated.");
[strongSelf->_configContent activatePersonalization];

// Update experiments only for 3p namespace
NSString *namespace = [strongSelf->_FIRNamespace
substringToIndex:[strongSelf->_FIRNamespace rangeOfString:@":"].location];
if ([namespace isEqualToString:FIRNamespaceGoogleMobilePlatform]) {
dispatch_async(dispatch_get_main_queue(), ^{
[self notifyConfigHasActivated];
});
[strongSelf->_configExperiment updateExperimentsWithHandler:^(NSError *_Nullable error) {
if (completion) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Expand All @@ -339,6 +345,19 @@ - (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completi
dispatch_async(_queue, applyBlock);
}

- (void)notifyConfigHasActivated {
// Need a valid google app name.
if (!_appName) {
return;
}
// The Remote Config Swift SDK will be listening for this notification so it can tell SwiftUI to
// update the UI.
NSDictionary *appInfoDict = @{kFIRAppNameKey : _appName};
[[NSNotificationCenter defaultCenter] postNotificationName:FIRRemoteConfigActivateNotification
object:self
userInfo:appInfoDict];
}

#pragma mark - helpers
- (NSString *)fullyQualifiedNamespace:(NSString *)namespace {
// If this is already a fully qualified namespace, return.
Expand Down
3 changes: 2 additions & 1 deletion FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

/// The timeout to set for outgoing fetch requests.
@property(nonatomic, readwrite, assign) NSTimeInterval fetchTimeout;

// The Google App ID of the configured FIRApp.
@property(nonatomic, readwrite, copy) NSString *googleAppID;
#pragma mark - Data required by config request.
/// Device authentication ID required by config request.
@property(nonatomic, copy) NSString *deviceAuthID;
Expand Down
5 changes: 4 additions & 1 deletion FirebaseRemoteConfigSwift.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ app update.
s.prefix_header_file = false

s.source_files = [
'FirebaseRemoteConfigSwift/Sources/*.swift',
'FirebaseRemoteConfigSwift/Sources/**/*.swift',
]

s.dependency 'FirebaseRemoteConfig', '~> 9.0'
Expand All @@ -53,6 +53,9 @@ app update.
'FirebaseRemoteConfigSwift/Tests/FakeUtils/*.swift',
'FirebaseRemoteConfigSwift/Tests/ObjC/*.[hm]',
]
# Excludes tests that cannot be include in API tests because it requires fetch remote values from
# a real console but only one test can be run without poluting other tests' remote values.
swift_api.exclude_files = ['FirebaseRemoteConfigSwift/Tests/SwiftAPI/PropertyWrapperTests.swift']
swift_api.resources = 'FirebaseRemoteConfigSwift/Tests/Defaults-testInfo.plist'
swift_api.requires_app_host = true
swift_api.pod_target_xcconfig = {
Expand Down
21 changes: 21 additions & 0 deletions FirebaseRemoteConfigSwift/Apps/SwiftUISample/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '14.0'

source 'https://github.com/firebase/SpecsDev.git'
source 'https://github.com/firebase/SpecsStaging.git'
source 'https://cdn.cocoapods.org/'

target 'SwiftUISample' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'FirebaseAnalytics'
pod 'FirebaseCore', :path => '../../../'
pod 'FirebaseCoreInternal', :path => '../../../'
pod 'FirebaseCoreDiagnostics', :path => '../../../'
pod 'FirebaseInstallations', :path => '../../../'
pod 'FirebaseRemoteConfig', :path => '../../../'
pod 'FirebaseRemoteConfigSwift', :path => '../../../'
pod 'FirebaseSharedSwift', :path => '../../..'
pod 'FirebaseABTesting', :path => '../../..'

end
Loading

0 comments on commit 9da2d37

Please sign in to comment.