Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated RC APIs #6637

Merged
merged 8 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions FirebaseRemoteConfig/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# v7.0.0
- [changed] Updated `lastFetchTime` field to readonly. (#6567)
- [changed] Functionally neutral change to stop using a deprecated method in the AB Testing API. (#6543)
- [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
123 changes: 14 additions & 109 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,12 @@ - (FIRRemoteConfigValue *)objectForKeyedSubscript:(NSString *)key {
}

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

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

__block FIRRemoteConfigValue *value;
dispatch_sync(_queue, ^{
value = self->_configContent.activeConfig[FQNamespace][key];
Expand All @@ -400,12 +342,7 @@ - (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 {
NSString *aNamespace = _FIRNamespace;
if (!key || !aNamespace) {
return [[FIRRemoteConfigValue alloc] initWithData:[NSData data]
source:FIRRemoteConfigSourceStatic];
Expand Down Expand Up @@ -441,8 +378,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 +387,6 @@ - (NSDate *)lastFetchTime {
});
return fetchTime;
}
#pragma clang diagnostic pop

- (FIRRemoteConfigFetchStatus)lastFetchStatus {
__block FIRRemoteConfigFetchStatus currentStatus;
Expand All @@ -463,10 +397,7 @@ - (FIRRemoteConfigFetchStatus)lastFetchStatus {
}

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

- (NSArray *)allKeysFromSource:(FIRRemoteConfigSource)source namespace:(NSString *)aNamespace {
NSString *aNamespace = _FIRNamespace;
__block NSArray *keys = [[NSArray alloc] init];
dispatch_sync(_queue, ^{
if (!aNamespace) {
Expand All @@ -492,11 +423,7 @@ - (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 {
NSString *aNamespace = _FIRNamespace;
__block NSMutableSet *keys = [[NSMutableSet alloc] init];
__block NSString *namespaceToCheck = aNamespace;
dispatch_sync(_queue, ^{
Expand All @@ -522,12 +449,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 {
- (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaultConfig {
NSString *aNamespace = _FIRNamespace;
if (!aNamespace) {
FIRLogWarning(kFIRLoggerRemoteConfig, @"I-RCN000036", @"The namespace cannot be empty or nil.");
return;
Expand All @@ -548,10 +471,7 @@ - (void)setDefaults:(NSDictionary<NSString *, NSObject *> *)defaultConfig
}

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

- (FIRRemoteConfigValue *)defaultValueForKey:(NSString *)key namespace:(NSString *)aNamespace {
NSString *aNamespace = _FIRNamespace;
if (!key || !aNamespace) {
return nil;
}
Expand All @@ -572,16 +492,11 @@ - (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 {
NSString *namespace = _FIRNamespace;
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 +510,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 +522,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 +546,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