Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ - (void)fetchWithExpirationDuration:(NSTimeInterval)expirationDuration
if (completionHandler) {
completionHandlerCopy = [completionHandler copy];
}
[_configFetch fetchAllConfigsWithExpirationDuration:expirationDuration
completionHandler:completionHandlerCopy];
[_configFetch fetchConfigWithExpirationDuration:expirationDuration
completionHandler:completionHandlerCopy];
}

#pragma mark - fetchAndActivate
Expand Down
2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
/// Throttling intervals are based on https://cloud.google.com/storage/docs/exponential-backoff
/// Returns true if client has fetched config and has not got back from server. This is used to
/// determine whether there is another config task infight when fetching.
@property(nonatomic, readwrite, assign) BOOL isFetchInProgress;
@property(atomic, readwrite, assign) BOOL isFetchInProgress;
/// Returns the current retry interval in seconds set for exponential backoff.
@property(nonatomic, readwrite, assign) double exponentialBackoffRetryInterval;
/// Returns the time in seconds until the next request is allowed while in exponential backoff mode.
Expand Down
6 changes: 3 additions & 3 deletions FirebaseRemoteConfig/Sources/RCNConfigFetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ typedef void (^RCNConfigFetcherTestBlock)(RCNConfigFetcherCompletion completion)
namespace:(NSString *)firebaseNamespace
options:(FIROptions *)firebaseOptions NS_DESIGNATED_INITIALIZER;

/// Fetches all config data keyed by namespace. Completion block will be called on the main queue.
/// Fetches config data keyed by namespace. Completion block will be called on the main queue.
/// @param expirationDuration Expiration duration, in seconds.
/// @param completionHandler Callback handler.
- (void)fetchAllConfigsWithExpirationDuration:(NSTimeInterval)expirationDuration
completionHandler:(FIRRemoteConfigFetchCompletion)completionHandler;
- (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration
completionHandler:(FIRRemoteConfigFetchCompletion)completionHandler;

/// Add the ability to update NSURLSession's timeout after a session has already been created.
- (void)recreateNetworkSession;
Expand Down
8 changes: 6 additions & 2 deletions FirebaseRemoteConfig/Sources/RCNFetch.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ - (void)dealloc {

#pragma mark - Fetch Config API

- (void)fetchAllConfigsWithExpirationDuration:(NSTimeInterval)expirationDuration
completionHandler:(FIRRemoteConfigFetchCompletion)completionHandler {
- (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration
completionHandler:(FIRRemoteConfigFetchCompletion)completionHandler {
// Note: We expect the googleAppID to always be available.
BOOL hasDeviceContextChanged =
FIRRemoteConfigHasDeviceContextChanged(_settings.deviceContext, _options.googleAppID);
Expand All @@ -139,6 +139,7 @@ - (void)fetchAllConfigsWithExpirationDuration:(NSTimeInterval)expirationDuration
RCNConfigFetch *fetchWithExpirationSelf = weakSelf;
dispatch_async(fetchWithExpirationSelf->_lockQueue, ^{
RCNConfigFetch *strongSelf = fetchWithExpirationSelf;

// Check whether we are outside of the minimum fetch interval.
if (![strongSelf->_settings hasMinimumFetchIntervalElapsed:expirationDuration] &&
!hasDeviceContextChanged) {
Expand All @@ -147,7 +148,10 @@ - (void)fetchAllConfigsWithExpirationDuration:(NSTimeInterval)expirationDuration
withStatus:FIRRemoteConfigFetchStatusSuccess
withError:nil];
}

// Check if a fetch is already in progress.
if (strongSelf->_settings.isFetchInProgress) {
// Check if we have some fetched data.
if (strongSelf->_settings.lastFetchTimeInterval > 0) {
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000052",
@"A fetch is already in progress. Using previous fetch results.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,36 +159,39 @@ - (IBAction)fetchButtonPressed:(id)sender {
- (IBAction)fetchAndActivateButtonPressed:(id)sender {
// fetchConfig api callback, this is triggered when client receives response from server
ViewController *__weak weakSelf = self;
FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion = ^(
FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
ViewController *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
NSMutableString *output = [NSMutableString
stringWithFormat:@"Fetch and activate status : %@.\n\n",
(status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote ||
status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData)
? @"Success"
: [NSString
stringWithFormat:@"Failure: %@", [error localizedDescription]]];
if (error) {
[output appendFormat:@"%@\n", error];
}
if (status == FIRRemoteConfigFetchAndActivateStatusError) {
[output appendString:[NSString stringWithFormat:@"Fetch And Activate Error :%@.\n",
[strongSelf errorString:error.code]]];
if (error.code == FIRRemoteConfigErrorThrottled) {
[output appendString:[NSString stringWithFormat:@"Throttled.\n"]];
}
}
// activate status
[[FRCLog sharedInstance] logToConsole:output];
if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote ||
status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData) {
[strongSelf printResult:[[NSMutableString alloc] init]];
}
};
FIRRemoteConfigFetchAndActivateCompletion fetchAndActivateCompletion =
^(FIRRemoteConfigFetchAndActivateStatus status, NSError *error) {
ViewController *strongSelf = weakSelf;
if (!strongSelf) {
return;
}
NSMutableString *output = @"Fetch and activate status :";
if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) {
[output appendString:@"Success from remote fetch."];
} else if (status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData) {
[output appendString:@"Success using pre-fetched data."];
} else if (status == FIRRemoteConfigFetchAndActivateStatusError) {
output appendString
: [NSString stringWithFormat:@"Failure: %@", [error localizedDescription]];
}

if (error) {
[output appendFormat:@"%@\n", error];
}
if (status == FIRRemoteConfigFetchAndActivateStatusError) {
[output appendString:[NSString stringWithFormat:@"Fetch And Activate Error :%@.\n",
[strongSelf errorString:error.code]]];
if (error.code == FIRRemoteConfigErrorThrottled) {
[output appendString:[NSString stringWithFormat:@"Throttled.\n"]];
}
}
// activate status
[[FRCLog sharedInstance] logToConsole:output];
if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote ||
status == FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData) {
[strongSelf printResult:[[NSMutableString alloc] init]];
}
};

// fetchConfig api call
[self.RCInstances[self.currentNamespace][self.FIRAppName]
Expand Down
9 changes: 3 additions & 6 deletions FirebaseRemoteConfig/Tests/Unit/RCNRemoteConfigTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ - (void)setUp {
namespace:fullyQualifiedNamespace
options:currentOptions]);

OCMStub([_configFetch[i] fetchAllConfigsWithExpirationDuration:43200
completionHandler:OCMOCK_ANY])
OCMStub([_configFetch[i] fetchConfigWithExpirationDuration:43200 completionHandler:OCMOCK_ANY])
.andDo(^(NSInvocation *invocation) {
void (^handler)(FIRRemoteConfigFetchStatus status, NSError *_Nullable error) = nil;
// void (^handler)(FIRRemoteConfigFetchCompletion);
Expand Down Expand Up @@ -498,8 +497,7 @@ - (void)testFetchConfigsFailed {
namespace:fullyQualifiedNamespace
options:currentOptions]);

OCMStub([_configFetch[i] fetchAllConfigsWithExpirationDuration:43200
completionHandler:OCMOCK_ANY])
OCMStub([_configFetch[i] fetchConfigWithExpirationDuration:43200 completionHandler:OCMOCK_ANY])
.andDo(^(NSInvocation *invocation) {
void (^handler)(FIRRemoteConfigFetchStatus status, NSError *_Nullable error) = nil;
// void (^handler)(FIRRemoteConfigFetchCompletion);
Expand Down Expand Up @@ -627,8 +625,7 @@ - (void)testActivateOnFetchNoChangeStatus {
namespace:fullyQualifiedNamespace
options:currentOptions]);

OCMStub([_configFetch[i] fetchAllConfigsWithExpirationDuration:43200
completionHandler:OCMOCK_ANY])
OCMStub([_configFetch[i] fetchConfigWithExpirationDuration:43200 completionHandler:OCMOCK_ANY])
.andDo(^(NSInvocation *invocation) {
void (^handler)(FIRRemoteConfigFetchStatus status, NSError *_Nullable error) = nil;

Expand Down