summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Rex <julian.rex@mapbox.com>2019-04-24 14:40:45 -0400
committerGitHub <noreply@github.com>2019-04-24 14:40:45 -0400
commit43553c37e98225d7951d0abb694b080075c1b4c4 (patch)
treef50aa8236a9116fff317421da3bf81e35074ebc5
parent88a652542715c595105589e8356754e11245e699 (diff)
downloadqtlocation-mapboxgl-43553c37e98225d7951d0abb694b080075c1b4c4.tar.gz
[ios] Enable/Disable sku token handling (#14467)
-rw-r--r--platform/darwin/src/MGLAccountManager.m43
-rw-r--r--platform/darwin/src/MGLAccountManager_Private.h3
-rw-r--r--platform/darwin/src/http_file_source.mm15
-rw-r--r--platform/ios/src/MGLMapboxEvents.m5
-rw-r--r--platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h6
-rw-r--r--platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.abin48440 -> 62456 bytes
6 files changed, 56 insertions, 16 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m
index 0566605323..edcfbbcdf0 100644
--- a/platform/darwin/src/MGLAccountManager.m
+++ b/platform/darwin/src/MGLAccountManager.m
@@ -10,6 +10,8 @@
#import "MBXSKUToken.h"
#endif
+static BOOL _MGLAccountsSDKEnabled;
+
@interface MGLAccountManager ()
@property (atomic) NSString *accessToken;
@@ -19,7 +21,6 @@
@property (atomic) NSString *skuToken;
@property (atomic) NSDate *skuTokenExpiration;
#endif
-
@end
@implementation MGLAccountManager
@@ -32,7 +33,7 @@
if (accessToken.length) {
self.accessToken = accessToken;
}
-
+
NSString *apiBaseURL = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"MGLMapboxAPIBaseURL"];
// If apiBaseURL is not a valid URL, [NSURL URLWithString:] will be `nil`.
@@ -41,7 +42,17 @@
}
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
- self.skuToken = [MBXSKUToken skuToken];
+ // 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;
+ }
+
#endif
}
@@ -101,15 +112,31 @@
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
-+ (void)setSkuToken:(NSString *)skuToken {
- NSTimeInterval oneHour = 60 * 60; // TODO: make this const
- MGLAccountManager.sharedManager.skuTokenExpiration = [NSDate dateWithTimeIntervalSinceNow:oneHour];
++ (BOOL)isAccountsSDKEnabled {
+ return _MGLAccountsSDKEnabled;
+}
- MGLAccountManager.sharedManager.skuToken = skuToken;
++ (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;
+ }
}
+ (NSString *)skuToken {
- return [MGLAccountManager.sharedManager isSKUTokenExpired] ? [MBXSKUToken skuToken] : MGLAccountManager.sharedManager.skuToken;
+ if (MGLAccountManager.isAccountsSDKEnabled) {
+ return [MGLAccountManager.sharedManager isSKUTokenExpired] ?
+ MBXSKUToken.mapsToken :
+ MGLAccountManager.sharedManager.skuToken;
+ }
+ else {
+ return nil;
+ }
}
- (BOOL)isSKUTokenExpired {
diff --git a/platform/darwin/src/MGLAccountManager_Private.h b/platform/darwin/src/MGLAccountManager_Private.h
index 3fd45f1ae8..366e3097f3 100644
--- a/platform/darwin/src/MGLAccountManager_Private.h
+++ b/platform/darwin/src/MGLAccountManager_Private.h
@@ -15,7 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
/// The current global SKU.
-@property (class, atomic, readonly) NSString *skuToken;
+@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 29f8f7db68..c4b18ffd3c 100644
--- a/platform/darwin/src/http_file_source.mm
+++ b/platform/darwin/src/http_file_source.mm
@@ -208,10 +208,17 @@ 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];
- NSArray *newQueryItems = @[
- [NSURLQueryItem queryItemWithName:@"events" value:@"true"],
- [NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken]
- ];
+
+ NSMutableArray *newQueryItems = [NSMutableArray arrayWithArray:@[
+ [NSURLQueryItem queryItemWithName:@"events" value:@"true"]
+ ]];
+
+ // 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");
+ [newQueryItems addObject:[NSURLQueryItem queryItemWithName:@"sku" value:MGLAccountManager.skuToken]];
+ }
components.queryItems = components.queryItems ? [components.queryItems arrayByAddingObjectsFromArray:newQueryItems] : newQueryItems;
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index 5cbb178c2c..bb16f77f98 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -1,6 +1,7 @@
#import "MGLMapboxEvents.h"
#import "MBXSKUToken.h"
#import "NSBundle+MGLAdditions.h"
+#import "MGLAccountManager_Private.h"
static NSString * const MGLAPIClientUserAgentBase = @"mapbox-maps-ios";
static NSString * const MGLMapboxAccountType = @"MGLMapboxAccountType";
@@ -144,7 +145,9 @@ static NSString * const MGLVariableGeofence = @"VariableGeofence";
[[MGLMapboxEvents sharedInstance] eventsManager].baseURL = [MGLMapboxEvents sharedInstance].baseURL;
}
- [[MGLMapboxEvents sharedInstance] eventsManager].skuId = MBXAccountsSKUIDMaps;
+ if (MGLAccountManager.isAccountsSDKEnabled) {
+ [[self sharedInstance] eventsManager].skuId = MBXAccountsMapsSKUIDMaps;
+ }
[self flush];
});
diff --git a/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h b/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
index 3a812c89ad..e83ffd2288 100644
--- a/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
+++ b/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
@@ -2,11 +2,13 @@
NS_ASSUME_NONNULL_BEGIN
-extern NSString *const MBXAccountsSKUIDMaps;
+extern NSString *const MBXAccountsMapsSKUIDMaps;
+extern NSString *const MBXAccountsNavigationSKUIDMaps;
@interface MBXSKUToken : NSObject
-+ (NSString *)skuToken;
+@property (class, nonatomic, readonly) NSString *mapsToken;
+@property (class, nonatomic, readonly) NSString *navigationToken;
@end
diff --git a/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a b/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
index e18e8ef4ef..678265bf35 100644
--- a/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
+++ b/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
Binary files differ