From 493ad10eb8cf582bfe3ff5b3290d677c7ab90121 Mon Sep 17 00:00:00 2001 From: Jason Wray Date: Mon, 20 May 2019 22:49:50 -0700 Subject: [ios] Enable SKU tokens for all requests Removes conditional code that relied on a plist flag. Other small cleanups. --- platform/darwin/src/MGLAccountManager.m | 42 +++++-------------------- platform/darwin/src/MGLAccountManager_Private.h | 3 +- platform/darwin/src/http_file_source.mm | 11 +------ platform/ios/app/Info.plist | 2 -- platform/ios/src/MGLMapboxEvents.m | 4 +-- 5 files changed, 11 insertions(+), 51 deletions(-) diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m index da2b99c9ac..cab9b16791 100644 --- a/platform/darwin/src/MGLAccountManager.m +++ b/platform/darwin/src/MGLAccountManager.m @@ -10,7 +10,7 @@ #import "MBXSKUToken.h" #endif -static BOOL _MGLAccountsSDKEnabled; +static const NSTimeInterval MGLAccountManagerSKUTokenLifespan = 3600; @interface MGLAccountManager () @@ -42,17 +42,7 @@ static BOOL _MGLAccountsSDKEnabled; } #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR - // TODO: Use MGL_OBJC_DYNAMIC_CAST (that requires moving the macro, where it - // doesn't require a C++ header) - NSNumber *accountsSDKNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAccountsSDKEnabled"]; - if ([accountsSDKNumber isKindOfClass:[NSNumber class]]) { - _MGLAccountsSDKEnabled = ((NSNumber*)accountsSDKNumber).boolValue; - } - - if (self.isAccountsSDKEnabled) { - self.skuToken = [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser]; - } - + self.skuToken = [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser]; #endif } @@ -112,35 +102,19 @@ static BOOL _MGLAccountsSDKEnabled; #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR -+ (BOOL)isAccountsSDKEnabled { - return _MGLAccountsSDKEnabled; -} - + (void)setSkuToken:(NSString *)skuToken { - if (MGLAccountManager.isAccountsSDKEnabled) { - NSTimeInterval oneHour = 60 * 60; // TODO: make this const - MGLAccountManager.sharedManager.skuTokenExpiration = [NSDate dateWithTimeIntervalSinceNow:oneHour]; - MGLAccountManager.sharedManager.skuToken = skuToken; - } - else { - MGLAccountManager.sharedManager.skuTokenExpiration = [NSDate distantFuture]; - MGLAccountManager.sharedManager.skuToken = nil; - } + MGLAccountManager.sharedManager.skuTokenExpiration = [NSDate dateWithTimeIntervalSinceNow:MGLAccountManagerSKUTokenLifespan]; + MGLAccountManager.sharedManager.skuToken = skuToken; } + (NSString *)skuToken { - if (MGLAccountManager.isAccountsSDKEnabled) { - return [MGLAccountManager.sharedManager isSKUTokenExpired] ? - [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser] : - MGLAccountManager.sharedManager.skuToken; - } - else { - return nil; - } + return [MGLAccountManager.sharedManager isSKUTokenExpired] ? + [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser] : + MGLAccountManager.sharedManager.skuToken; } - (BOOL)isSKUTokenExpired { - NSTimeInterval secondsUntilExpiration = [MGLAccountManager.sharedManager.skuTokenExpiration timeIntervalSinceDate:NSDate.date]; + NSTimeInterval secondsUntilExpiration = [MGLAccountManager.sharedManager.skuTokenExpiration timeIntervalSinceNow]; return secondsUntilExpiration < 0; } diff --git a/platform/darwin/src/MGLAccountManager_Private.h b/platform/darwin/src/MGLAccountManager_Private.h index 366e3097f3..3fd45f1ae8 100644 --- a/platform/darwin/src/MGLAccountManager_Private.h +++ b/platform/darwin/src/MGLAccountManager_Private.h @@ -15,8 +15,7 @@ NS_ASSUME_NONNULL_BEGIN #if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR /// The current global SKU. -@property (class, atomic, readonly, nullable) NSString *skuToken; -@property (class, nonatomic, readonly) BOOL isAccountsSDKEnabled; +@property (class, atomic, readonly) NSString *skuToken; #endif @end diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 20b9ead7af..0d14c44c01 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -208,16 +208,7 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, if (impl->accountType == 0 && ([url.host isEqualToString:@"mapbox.com"] || [url.host hasSuffix:@".mapbox.com"])) { NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO]; - NSURLQueryItem *accountsQueryItem = nil; - - // Only add the token if we have enabled the accounts SDK - if (MGLAccountManager.isAccountsSDKEnabled) { - NSCAssert(MGLAccountManager.skuToken, @"skuToken should be non-nil if the accounts SDK is enabled"); - accountsQueryItem = [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken]; - } else { - accountsQueryItem = [NSURLQueryItem queryItemWithName:@"events" value:@"true"]; - } - + NSURLQueryItem *accountsQueryItem = [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken]; components.queryItems = components.queryItems ? [components.queryItems arrayByAddingObject:accountsQueryItem] : @[accountsQueryItem]; url = components.URL; } diff --git a/platform/ios/app/Info.plist b/platform/ios/app/Info.plist index a30b62a862..e2f294a5a5 100644 --- a/platform/ios/app/Info.plist +++ b/platform/ios/app/Info.plist @@ -66,7 +66,5 @@ settings - MGLMapboxAccountsSDKEnabled - diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m index 337929c7ec..d5814dab46 100644 --- a/platform/ios/src/MGLMapboxEvents.m +++ b/platform/ios/src/MGLMapboxEvents.m @@ -145,9 +145,7 @@ static NSString * const MGLVariableGeofence = @"VariableGeofence"; [[MGLMapboxEvents sharedInstance] eventsManager].baseURL = [MGLMapboxEvents sharedInstance].baseURL; } - if (MGLAccountManager.isAccountsSDKEnabled) { - [[self sharedInstance] eventsManager].skuId = MBXAccountsSKUIDMaps; - } + [[self sharedInstance] eventsManager].skuId = MBXAccountsSKUIDMaps; [self flush]; }); -- cgit v1.2.1