Skip to content

Commit

Permalink
Remove deprecated RC APIs (#6637)
Browse files Browse the repository at this point in the history
* Remove deprecated method declarations and implementations
  • Loading branch information
karenyz authored Oct 1, 2020
1 parent 69bfe3f commit f56afe9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 250 deletions.
1 change: 1 addition & 0 deletions FirebaseRemoteConfig/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- [changed] Updated `lastFetchTime` field to readonly. (#6567)
- [changed] Functionally neutral change to stop using a deprecated method in the AB Testing API. (#6543)
- [fixed] Updated `numberValue` to be nonnull to align with current behavior. (#6623)
- [removed] Removed deprecated APIs `isDeveloperModeEnabled`, `initWithDeveloperModeEnabled:developerModeEnabled`, `activateWithCompletionHandler:completionHandler`, `activateFetched`, `configValueForKey:namespace`, `configValueForKey:namespace:source`, `allKeysFromSource:namespace`, `keysWithPrefix:namespace`, `setDefaults:namespace`, `setDefaultsFromPlistFileName:namespace`, `defaultValueForKey:namespace`. (#6637)

# v4.9.1
- [fixed] Fix an `attempt to insert nil object` crash in `fetchWithExpirationDuration:`. (#6522)
Expand Down
150 changes: 15 additions & 135 deletions FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,17 @@ @interface FIRRemoteConfigSettings () {
}
@end

// Implementations depend upon multiple deprecated APIs
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"

@implementation FIRRemoteConfigSettings
- (instancetype)initWithDeveloperModeEnabled:(BOOL)developerModeEnabled {
self = [self init];
if (self) {
_developerModeEnabled = developerModeEnabled;
}
return self;
}

- (instancetype)init {
self = [super init];
if (self) {
_developerModeEnabled = NO;
_minimumFetchInterval = RCNDefaultMinimumFetchInterval;
_fetchTimeout = RCNHTTPDefaultConnectionTimeout;
}
return self;
}

- (BOOL)isDeveloperModeEnabled {
return _developerModeEnabled;
}

@end

@implementation FIRRemoteConfig {
Expand Down Expand Up @@ -241,7 +225,7 @@ - (void)fetchAndActivateWithCompletionHandler:
// Fetch completed. We are being called on the main queue.
// If fetch is successful, try to activate the fetched config
if (fetchStatus == FIRRemoteConfigFetchStatusSuccess && !fetchError) {
[strongSelf activateWithCompletionHandler:^(NSError *_Nullable activateError) {
[strongSelf activateWithCompletion:^(BOOL changed, NSError *_Nullable activateError) {
if (completionHandler) {
FIRRemoteConfigFetchAndActivateStatus status =
activateError ? FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData
Expand All @@ -262,31 +246,9 @@ - (void)fetchAndActivateWithCompletionHandler:

#pragma mark - apply

- (BOOL)activateFetched {
// TODO: We block on the async activate to complete. This method is deprecated and needs
// to be removed at the next possible breaking change.
__block dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
__block BOOL didActivate = NO;
[self activateWithCompletionHandler:^(NSError *_Nullable error) {
didActivate = error ? false : true;
dispatch_semaphore_signal(semaphore);
}];
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return didActivate;
}

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

- (void)activateWithCompletion:(FIRRemoteConfigActivateChangeCompletion)completion {
[self activateWithEitherHandler:completion deprecatedHandler:nil];
}

- (void)activateWithCompletionHandler:(FIRRemoteConfigActivateCompletion)completionHandler {
[self activateWithEitherHandler:nil deprecatedHandler:completionHandler];
}

- (void)activateWithEitherHandler:(FIRRemoteConfigActivateChangeCompletion)completion
deprecatedHandler:(FIRRemoteConfigActivateCompletion)deprecatedHandler {
__weak FIRRemoteConfig *weakSelf = self;
void (^applyBlock)(void) = ^(void) {
FIRRemoteConfig *strongSelf = weakSelf;
Expand All @@ -298,8 +260,6 @@ - (void)activateWithEitherHandler:(FIRRemoteConfigActivateChangeCompletion)compl
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
completion(NO, error);
});
} else if (deprecatedHandler) {
deprecatedHandler(error);
}
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000068", @"Internal error activating config.");
return;
Expand All @@ -314,16 +274,6 @@ - (void)activateWithEitherHandler:(FIRRemoteConfigActivateChangeCompletion)compl
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
completion(NO, nil);
});
} else if (deprecatedHandler) {
NSError *error = [NSError
errorWithDomain:FIRRemoteConfigErrorDomain
code:FIRRemoteConfigErrorInternalError
userInfo:@{
@"ActivationFailureReason" : @"Most recently fetched config already activated"
}];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
deprecatedHandler(error);
});
}
return;
}
Expand All @@ -337,10 +287,6 @@ - (void)activateWithEitherHandler:(FIRRemoteConfigActivateChangeCompletion)compl
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
completion(YES, nil);
});
} else if (deprecatedHandler) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
deprecatedHandler(nil);
});
}
};
dispatch_async(_queue, applyBlock);
Expand All @@ -367,16 +313,11 @@ - (FIRRemoteConfigValue *)objectForKeyedSubscript:(NSString *)key {
}

- (FIRRemoteConfigValue *)configValueForKey:(NSString *)key {
return [self configValueForKey:key namespace:_FIRNamespace];
}

- (FIRRemoteConfigValue *)configValueForKey:(NSString *)key namespace:(NSString *)aNamespace {
if (!key || !aNamespace) {
if (!key) {
return [[FIRRemoteConfigValue alloc] initWithData:[NSData data]
source:FIRRemoteConfigSourceStatic];
}
NSString *FQNamespace = [self fullyQualifiedNamespace:aNamespace];

NSString *FQNamespace = [self fullyQualifiedNamespace:_FIRNamespace];
__block FIRRemoteConfigValue *value;
dispatch_sync(_queue, ^{
value = self->_configContent.activeConfig[FQNamespace][key];
Expand All @@ -400,17 +341,11 @@ - (FIRRemoteConfigValue *)configValueForKey:(NSString *)key namespace:(NSString
}

- (FIRRemoteConfigValue *)configValueForKey:(NSString *)key source:(FIRRemoteConfigSource)source {
return [self configValueForKey:key namespace:_FIRNamespace source:source];
}

- (FIRRemoteConfigValue *)configValueForKey:(NSString *)key
namespace:(NSString *)aNamespace
source:(FIRRemoteConfigSource)source {
if (!key || !aNamespace) {
if (!key) {
return [[FIRRemoteConfigValue alloc] initWithData:[NSData data]
source:FIRRemoteConfigSourceStatic];
}
NSString *FQNamespace = [self fullyQualifiedNamespace:aNamespace];
NSString *FQNamespace = [self fullyQualifiedNamespace:_FIRNamespace];

__block FIRRemoteConfigValue *value;
dispatch_sync(_queue, ^{
Expand Down Expand Up @@ -441,8 +376,6 @@ - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state

#pragma mark - Properties

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-property-ivar"
/// Last fetch completion time.
- (NSDate *)lastFetchTime {
__block NSDate *fetchTime;
Expand All @@ -452,7 +385,6 @@ - (NSDate *)lastFetchTime {
});
return fetchTime;
}
#pragma clang diagnostic pop

- (FIRRemoteConfigFetchStatus)lastFetchStatus {
__block FIRRemoteConfigFetchStatus currentStatus;
Expand All @@ -463,16 +395,9 @@ - (FIRRemoteConfigFetchStatus)lastFetchStatus {
}

- (NSArray *)allKeysFromSource:(FIRRemoteConfigSource)source {
return [self allKeysFromSource:source namespace:_FIRNamespace];
}

- (NSArray *)allKeysFromSource:(FIRRemoteConfigSource)source namespace:(NSString *)aNamespace {
__block NSArray *keys = [[NSArray alloc] init];
dispatch_sync(_queue, ^{
if (!aNamespace) {
return;
}
NSString *FQNamespace = [self fullyQualifiedNamespace:aNamespace];
NSString *FQNamespace = [self fullyQualifiedNamespace:self->_FIRNamespace];
switch (source) {
case FIRRemoteConfigSourceDefault:
if (self->_configContent.defaultConfig[FQNamespace]) {
Expand All @@ -492,18 +417,9 @@ - (NSArray *)allKeysFromSource:(FIRRemoteConfigSource)source namespace:(NSString
}

- (nonnull NSSet *)keysWithPrefix:(nullable NSString *)prefix {
return [self keysWithPrefix:prefix namespace:_FIRNamespace];
}

- (nonnull NSSet *)keysWithPrefix:(nullable NSString *)prefix
namespace:(nullable NSString *)aNamespace {
__block NSMutableSet *keys = [[NSMutableSet alloc] init];
__block NSString *namespaceToCheck = aNamespace;
dispatch_sync(_queue, ^{
if (!namespaceToCheck.length) {
return;
}
NSString *FQNamespace = [self fullyQualifiedNamespace:namespaceToCheck];
NSString *FQNamespace = [self fullyQualifiedNamespace:self->_FIRNamespace];
if (self->_configContent.activeConfig[FQNamespace]) {
NSArray *allKeys = [self->_configContent.activeConfig[FQNamespace] allKeys];
if (!prefix.length) {
Expand All @@ -522,17 +438,8 @@ - (nonnull NSSet *)keysWithPrefix:(nullable NSString *)prefix

#pragma mark - Defaults

- (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaults {
[self setDefaults:defaults namespace:_FIRNamespace];
}

- (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaultConfig
namespace:(NSString *)aNamespace {
if (!aNamespace) {
FIRLogWarning(kFIRLoggerRemoteConfig, @"I-RCN000036", @"The namespace cannot be empty or nil.");
return;
}
NSString *FQNamespace = [self fullyQualifiedNamespace:aNamespace];
- (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaultConfig {
NSString *FQNamespace = [self fullyQualifiedNamespace:_FIRNamespace];
NSDictionary *defaultConfigCopy = [[NSDictionary alloc] init];
if (defaultConfig) {
defaultConfigCopy = [defaultConfig copy];
Expand All @@ -548,14 +455,7 @@ - (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaultConfig
}

- (FIRRemoteConfigValue *)defaultValueForKey:(NSString *)key {
return [self defaultValueForKey:key namespace:_FIRNamespace];
}

- (FIRRemoteConfigValue *)defaultValueForKey:(NSString *)key namespace:(NSString *)aNamespace {
if (!key || !aNamespace) {
return nil;
}
NSString *FQNamespace = [self fullyQualifiedNamespace:aNamespace];
NSString *FQNamespace = [self fullyQualifiedNamespace:_FIRNamespace];
__block FIRRemoteConfigValue *value;
dispatch_sync(_queue, ^{
NSDictionary *defaultConfig = self->_configContent.defaultConfig;
Expand All @@ -572,16 +472,6 @@ - (FIRRemoteConfigValue *)defaultValueForKey:(NSString *)key namespace:(NSString
}

- (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName {
return [self setDefaultsFromPlistFileName:fileName namespace:_FIRNamespace];
}

- (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName
namespace:(nullable NSString *)namespace {
if (!namespace || namespace.length == 0) {
FIRLogWarning(kFIRLoggerRemoteConfig, @"I-RCN000036", @"The namespace cannot be empty or nil.");
return;
}
NSString *FQNamespace = [self fullyQualifiedNamespace:namespace];
if (!fileName || fileName.length == 0) {
FIRLogWarning(kFIRLoggerRemoteConfig, @"I-RCN000037",
@"The plist file '%@' could not be found by Remote Config.", fileName);
Expand All @@ -595,7 +485,7 @@ - (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName
if (plistFile) {
NSDictionary *defaultConfig = [[NSDictionary alloc] initWithContentsOfFile:plistFile];
if (defaultConfig) {
[self setDefaults:defaultConfig namespace:FQNamespace];
[self setDefaults:defaultConfig];
}
return;
}
Expand All @@ -607,20 +497,17 @@ - (void)setDefaultsFromPlistFileName:(nullable NSString *)fileName
#pragma mark - custom variables

- (FIRRemoteConfigSettings *)configSettings {
__block BOOL developerModeEnabled = NO;
__block NSTimeInterval minimumFetchInterval = RCNDefaultMinimumFetchInterval;
__block NSTimeInterval fetchTimeout = RCNHTTPDefaultConnectionTimeout;
dispatch_sync(_queue, ^{
developerModeEnabled = [self->_settings.customVariables[kRemoteConfigDeveloperKey] boolValue];
minimumFetchInterval = self->_settings.minimumFetchInterval;
fetchTimeout = self->_settings.fetchTimeout;
});
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000066",
@"Successfully read configSettings. Developer Mode: %@, Minimum Fetch Interval:%f, "
@"Successfully read configSettings. Minimum Fetch Interval:%f, "
@"Fetch timeout: %f",
developerModeEnabled ? @"true" : @"false", minimumFetchInterval, fetchTimeout);
FIRRemoteConfigSettings *settings =
[[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:developerModeEnabled];
minimumFetchInterval, fetchTimeout);
FIRRemoteConfigSettings *settings = [[FIRRemoteConfigSettings alloc] init];
settings.minimumFetchInterval = minimumFetchInterval;
settings.fetchTimeout = fetchTimeout;
/// The NSURLSession needs to be recreated whenever the fetch timeout may be updated.
Expand All @@ -634,23 +521,16 @@ - (void)setConfigSettings:(FIRRemoteConfigSettings *)configSettings {
return;
}

NSDictionary *settingsToSave = @{
kRemoteConfigDeveloperKey : @(configSettings.isDeveloperModeEnabled),
};
self->_settings.customVariables = settingsToSave;
self->_settings.minimumFetchInterval = configSettings.minimumFetchInterval;
self->_settings.fetchTimeout = configSettings.fetchTimeout;
/// The NSURLSession needs to be recreated whenever the fetch timeout may be updated.
[self->_configFetch recreateNetworkSession];
FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000067",
@"Successfully set configSettings. Developer Mode: %@, Minimum Fetch Interval:%f, "
@"Successfully set configSettings. Minimum Fetch Interval:%f, "
@"Fetch timeout:%f",
configSettings.isDeveloperModeEnabled ? @"true" : @"false",
configSettings.minimumFetchInterval, configSettings.fetchTimeout);
};
dispatch_async(_queue, setConfigSettingsBlock);
}

#pragma clang diagnostic push // "-Wdeprecated-declarations"

@end
Loading

0 comments on commit f56afe9

Please sign in to comment.