summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-05-02 16:42:43 -0700
committerJason Wray <jason@mapbox.com>2019-05-16 15:48:08 -0700
commit98b2eb5b8856d8890aea3c6e84f675fcbcfef47e (patch)
treebd0f4d878f7a73ab45baab080321a8ed8f720d04
parenta0467ca76de259f372cf9360ea403d07276e4008 (diff)
downloadqtlocation-mapboxgl-98b2eb5b8856d8890aea3c6e84f675fcbcfef47e.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.m42
-rw-r--r--platform/darwin/src/MGLAccountManager_Private.h1
-rw-r--r--platform/darwin/src/http_file_source.mm11
-rw-r--r--platform/ios/app/Info.plist2
-rw-r--r--platform/ios/src/MGLMapboxEvents.m4
5 files changed, 10 insertions, 50 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..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 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];
});