diff options
author | Jason Wray <jason@mapbox.com> | 2019-05-02 16:42:43 -0700 |
---|---|---|
committer | Jason Wray <jason@mapbox.com> | 2019-05-13 16:36:08 -0700 |
commit | 3286fb519d39aaa1e1b2e4032633e1b1bd1ddfb9 (patch) | |
tree | 492409dbce95813dddd48227fea396bd6c782a8c | |
parent | cd24f4c45f6b38e7f3dc73cf0afda9b86b3d85d4 (diff) | |
download | qtlocation-mapboxgl-3286fb519d39aaa1e1b2e4032633e1b1bd1ddfb9.tar.gz |
[ios] Enable SKU tokens for all requests
Removes conditional code that relied on a plist flag. Other small cleanups.
-rw-r--r-- | platform/darwin/src/MGLAccountManager.m | 40 | ||||
-rw-r--r-- | platform/darwin/src/MGLAccountManager_Private.h | 1 | ||||
-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, 8 insertions, 50 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m index edcfbbcdf0..bc3e9d2369 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.mapsToken; - } - + self.skuToken = MBXSKUToken.mapsToken; #endif } @@ -112,35 +102,17 @@ 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.mapsToken : - MGLAccountManager.sharedManager.skuToken; - } - else { - return nil; - } + return [MGLAccountManager.sharedManager isSKUTokenExpired] ? MBXSKUToken.mapsToken : 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..6afcf356af 100644 --- a/platform/darwin/src/MGLAccountManager_Private.h +++ b/platform/darwin/src/MGLAccountManager_Private.h @@ -16,7 +16,6 @@ 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; #endif @end diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 26f6149b3f..afed7a914e 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 bb16f77f98..dc6391df07 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 = MBXAccountsMapsSKUIDMaps; - } + [[self sharedInstance] eventsManager].skuId = MBXAccountsMapsSKUIDMaps; [self flush]; }); |