summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Wray <jason@mapbox.com>2019-05-29 13:07:00 -0700
committerJason Wray <jason@mapbox.com>2019-06-04 19:57:12 -0700
commit1f51b564c42a87f3e2938841c7a241b52cf0332e (patch)
treebff6ff6e7877fd8f5cc63a52717bf4db2d19860f
parent012e3931bf1060df89923404ea9324f170139797 (diff)
downloadqtlocation-mapboxgl-1f51b564c42a87f3e2938841c7a241b52cf0332e.tar.gz
WIP accounts library v2 integration
-rw-r--r--platform/darwin/src/MGLAccountManager.m36
-rw-r--r--platform/ios/src/MGLMapboxEvents.m2
-rw-r--r--platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h30
-rw-r--r--platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.abin74248 -> 96784 bytes
4 files changed, 38 insertions, 30 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m
index cab9b16791..ca23825984 100644
--- a/platform/darwin/src/MGLAccountManager.m
+++ b/platform/darwin/src/MGLAccountManager.m
@@ -8,9 +8,10 @@
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
#import "MGLMapboxEvents.h"
#import "MBXSKUToken.h"
-#endif
-static const NSTimeInterval MGLAccountManagerSKUTokenLifespan = 3600;
+static NSString * const MGLAccountManagerExternalClassName = @"MBXAccounts";
+static NSString * const MGLAccountManagerExternalMethodName = @"skuToken";
+#endif
@interface MGLAccountManager ()
@@ -18,9 +19,11 @@ static const NSTimeInterval MGLAccountManagerSKUTokenLifespan = 3600;
@property (nonatomic) NSURL *apiBaseURL;
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
-@property (atomic) NSString *skuToken;
-@property (atomic) NSDate *skuTokenExpiration;
+@property BOOL useExternalAccountManager;
+@property id externalAccountsClass;
+@property SEL externalSKUTokenMethod;
#endif
+
@end
@implementation MGLAccountManager
@@ -42,7 +45,14 @@ static const NSTimeInterval MGLAccountManagerSKUTokenLifespan = 3600;
}
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
- self.skuToken = [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser];
+ // Check if we should use an external accounts library (e.g., provided by navigation)
+ id externalAccountsClass = NSClassFromString(MGLAccountManagerExternalClassName);
+ SEL externalSKUTokenMethod = NSSelectorFromString(MGLAccountManagerExternalMethodName);
+ if (externalAccountsClass != nil && [externalAccountsClass respondsToSelector:externalSKUTokenMethod]) {
+ MGLAccountManager.sharedManager.useExternalAccountManager = YES;
+ MGLAccountManager.sharedManager.externalAccountsClass = externalAccountsClass;
+ MGLAccountManager.sharedManager.externalSKUTokenMethod = externalSKUTokenMethod;
+ }
#endif
}
@@ -102,20 +112,10 @@ static const NSTimeInterval MGLAccountManagerSKUTokenLifespan = 3600;
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
-+ (void)setSkuToken:(NSString *)skuToken {
- MGLAccountManager.sharedManager.skuTokenExpiration = [NSDate dateWithTimeIntervalSinceNow:MGLAccountManagerSKUTokenLifespan];
- MGLAccountManager.sharedManager.skuToken = skuToken;
-}
-
+ (NSString *)skuToken {
- return [MGLAccountManager.sharedManager isSKUTokenExpired] ?
- [MBXSKUToken tokenForSKUID:MBXAccountsSKUIDMaps type:MBXAccountsSKUTypeUser] :
- MGLAccountManager.sharedManager.skuToken;
-}
-
-- (BOOL)isSKUTokenExpired {
- NSTimeInterval secondsUntilExpiration = [MGLAccountManager.sharedManager.skuTokenExpiration timeIntervalSinceNow];
- return secondsUntilExpiration < 0;
+ return MGLAccountManager.sharedManager.useExternalAccountManager ?
+ [MGLAccountManager.sharedManager.externalAccountsClass performSelector:MGLAccountManager.sharedManager.externalSKUTokenMethod] :
+ MBXSKUToken.skuToken;
}
#endif
diff --git a/platform/ios/src/MGLMapboxEvents.m b/platform/ios/src/MGLMapboxEvents.m
index d5814dab46..edf1dffa40 100644
--- a/platform/ios/src/MGLMapboxEvents.m
+++ b/platform/ios/src/MGLMapboxEvents.m
@@ -145,7 +145,7 @@ static NSString * const MGLVariableGeofence = @"VariableGeofence";
[[MGLMapboxEvents sharedInstance] eventsManager].baseURL = [MGLMapboxEvents sharedInstance].baseURL;
}
- [[self sharedInstance] eventsManager].skuId = MBXAccountsSKUIDMaps;
+ [[self sharedInstance] eventsManager].skuId = MBXAccountsSKUIDMapsUser;
[self flush];
});
diff --git a/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h b/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
index 8a02d9641c..c93b323b06 100644
--- a/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
+++ b/platform/ios/vendor/mapbox-accounts-ios/MBXSKUToken.h
@@ -3,25 +3,33 @@
NS_ASSUME_NONNULL_BEGIN
typedef NSString *MBXAccountsSKUID NS_TYPED_ENUM;
-FOUNDATION_EXTERN const MBXAccountsSKUID MBXAccountsSKUIDMaps;
-FOUNDATION_EXTERN const MBXAccountsSKUID MBXAccountsSKUIDNavigation;
+FOUNDATION_EXTERN const MBXAccountsSKUID MBXAccountsSKUIDMapsUser;
+FOUNDATION_EXTERN const MBXAccountsSKUID MBXAccountsSKUIDNavigationUser;
+FOUNDATION_EXTERN const MBXAccountsSKUID MBXAccountsSKUIDNavigationSession;
-typedef NS_ENUM(NSInteger, MBXAccountsSKUType) {
- MBXAccountsSKUTypeUser,
- MBXAccountsSKUTypeSession
-};
@interface MBXSKUToken : NSObject
/**
- Generates a token for the given identifier and type.
+ Activates a specific SKU identifier.
- @param skuId The sku identifier, e.g. maps or navigation.
- @param type The type of token, e.g. user or session.
+ Defaults to `MBXAccountsSKUIDMapsUser`.
- @return A SKU token for use with API requests.
+ See https://www.mapbox.com/pricing/ for more information
*/
-+ (NSString *)tokenForSKUID:(MBXAccountsSKUID)skuId type:(MBXAccountsSKUType)type NS_SWIFT_NAME(token(for:type:));
++ (void)activateSKUID:(MBXAccountsSKUID)skuId;
+
+/**
+ Resets the current session. Calling this method has no effect unless the type
+ of the SKU id is of kind session.
+ */
++ (void)resetSession;
+
+/**
+ Returns the current SKU token. `+[MBXSKUToken activateSKUID:]` must be called
+ before accessing this property unless an `MBXAccountsSKUIDMapsUser` token is preferred.
+ */
+@property (class, nonatomic, readonly) NSString *skuToken;
@end
diff --git a/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a b/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
index b57e17d47f..13288e6550 100644
--- a/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
+++ b/platform/ios/vendor/mapbox-accounts-ios/libmbxaccounts.a
Binary files differ