diff options
author | Jason Wray <friedbunny@users.noreply.github.com> | 2019-05-20 22:49:50 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-20 22:49:50 -0700 |
commit | 29140f5b119c3c9cbe7348ecb0f89f05282821a5 (patch) | |
tree | 542af13dd22c7f791401dd4c8ee3aff9946a6119 /platform | |
parent | 3cd8c6c1fda6c7691e0a71b6ef7a393ea0e50108 (diff) | |
download | qtlocation-mapboxgl-29140f5b119c3c9cbe7348ecb0f89f05282821a5.tar.gz |
[ios] Enable SKU tokens for all requests
Removes conditional code that relied on a plist flag. Other small cleanups.
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/src/MGLAccountManager.m | 42 | ||||
-rw-r--r-- | platform/darwin/src/MGLAccountManager_Private.h | 3 | ||||
-rw-r--r-- | platform/darwin/src/http_file_source.mm | 11 | ||||
-rw-r--r-- | platform/ios/app/Info.plist | 2 | ||||
-rw-r--r-- | 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<AsyncRequest> 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 @@ <string>settings</string> </dict> </array> - <key>MGLMapboxAccountsSDKEnabled</key> - <true/> </dict> </plist> 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]; }); |