[ios] get sku token return value
This commit is contained in:
@@ -18,10 +18,6 @@ static NSString * const MGLAccountManagerExternalMethodName = @"skuToken";
|
||||
@property (atomic) NSString *accessToken;
|
||||
@property (nonatomic) NSURL *apiBaseURL;
|
||||
|
||||
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
|
||||
@property BOOL useExternalAccountManager;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
@implementation MGLAccountManager
|
||||
@@ -41,15 +37,6 @@ static NSString * const MGLAccountManagerExternalMethodName = @"skuToken";
|
||||
if (apiBaseURL.length && [NSURL URLWithString:apiBaseURL]) {
|
||||
[self setAPIBaseURL:[NSURL URLWithString:apiBaseURL]];
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
|
||||
// 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;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (instancetype)sharedManager {
|
||||
@@ -109,13 +96,13 @@ static NSString * const MGLAccountManagerExternalMethodName = @"skuToken";
|
||||
#if TARGET_OS_IPHONE || TARGET_OS_SIMULATOR
|
||||
|
||||
+ (NSString *)skuToken {
|
||||
if (MGLAccountManager.sharedManager.useExternalAccountManager) {
|
||||
id externalAccountsClass = NSClassFromString(MGLAccountManagerExternalClassName);
|
||||
SEL externalSKUTokenMethod = NSSelectorFromString(MGLAccountManagerExternalMethodName);
|
||||
return ((NSString *(*)(id, SEL))[externalAccountsClass methodForSelector:externalSKUTokenMethod])(externalAccountsClass, externalSKUTokenMethod);
|
||||
} else {
|
||||
return MBXSKUToken.skuToken;
|
||||
Class mbx = NSClassFromString(MGLAccountManagerExternalClassName);
|
||||
|
||||
if ([mbx respondsToSelector:NSSelectorFromString(MGLAccountManagerExternalMethodName)]) {
|
||||
return (NSString *)[mbx valueForKeyPath:MGLAccountManagerExternalMethodName];
|
||||
}
|
||||
|
||||
return MBXSKUToken.skuToken;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
350098DD1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 350098DA1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h */; };
|
||||
350098DE1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 350098DB1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm */; };
|
||||
350098DF1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 350098DB1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm */; };
|
||||
3502D6CC22AE88D5006BDFCE /* MGLAccountManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3502D6CB22AE88D5006BDFCE /* MGLAccountManagerTests.m */; };
|
||||
3510FFEA1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3510FFE81D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h */; };
|
||||
3510FFEB1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3510FFE81D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h */; };
|
||||
3510FFEC1D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.mm in Sources */ = {isa = PBXBuildFile; fileRef = 3510FFE91D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.mm */; };
|
||||
@@ -910,6 +911,7 @@
|
||||
350098BA1D480108004B2AF0 /* MGLVectorTileSource.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MGLVectorTileSource.mm; sourceTree = "<group>"; };
|
||||
350098DA1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSValue+MGLStyleAttributeAdditions.h"; sourceTree = "<group>"; };
|
||||
350098DB1D484E60004B2AF0 /* NSValue+MGLStyleAttributeAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSValue+MGLStyleAttributeAdditions.mm"; sourceTree = "<group>"; };
|
||||
3502D6CB22AE88D5006BDFCE /* MGLAccountManagerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLAccountManagerTests.m; sourceTree = "<group>"; };
|
||||
3510FFE81D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSComparisonPredicate+MGLAdditions.h"; sourceTree = "<group>"; };
|
||||
3510FFE91D6D9C7A00F413B2 /* NSComparisonPredicate+MGLAdditions.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "NSComparisonPredicate+MGLAdditions.mm"; sourceTree = "<group>"; };
|
||||
3510FFEE1D6D9D8C00F413B2 /* NSExpression+MGLAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSExpression+MGLAdditions.h"; sourceTree = "<group>"; };
|
||||
@@ -2006,6 +2008,7 @@
|
||||
4031ACFD1E9FD26900A3EA26 /* Test Helpers */,
|
||||
409F43FB1E9E77D10048729D /* Swift Integration */,
|
||||
357579811D502AD4000B822E /* Styling */,
|
||||
3502D6CB22AE88D5006BDFCE /* MGLAccountManagerTests.m */,
|
||||
353D23951D0B0DFE002BE09D /* MGLAnnotationViewTests.m */,
|
||||
DAEDC4331D603417000224FF /* MGLAttributionInfoTests.m */,
|
||||
DA35A2C31CCA9F8300E826B2 /* MGLClockDirectionFormatterTests.m */,
|
||||
@@ -3238,6 +3241,7 @@
|
||||
FAE1CDCB1E9D79CB00C40B5B /* MGLFillExtrusionStyleLayerTests.mm in Sources */,
|
||||
DA35A2AA1CCA058D00E826B2 /* MGLCoordinateFormatterTests.m in Sources */,
|
||||
357579831D502AE6000B822E /* MGLRasterStyleLayerTests.mm in Sources */,
|
||||
3502D6CC22AE88D5006BDFCE /* MGLAccountManagerTests.m in Sources */,
|
||||
DAF25720201902BC00367EF5 /* MGLHillshadeStyleLayerTests.mm in Sources */,
|
||||
353D23961D0B0DFE002BE09D /* MGLAnnotationViewTests.m in Sources */,
|
||||
DA0CD5901CF56F6A00A5F5A5 /* MGLFeatureTests.mm in Sources */,
|
||||
|
||||
25
platform/ios/test/MGLAccountManagerTests.m
Normal file
25
platform/ios/test/MGLAccountManagerTests.m
Normal file
@@ -0,0 +1,25 @@
|
||||
#import <XCTest/XCTest.h>
|
||||
#import <Mapbox/Mapbox.h>
|
||||
|
||||
@interface MBXAccounts: NSObject
|
||||
@property (class, nonatomic, readonly) NSString *skuToken;
|
||||
@end
|
||||
|
||||
@implementation MBXAccounts
|
||||
|
||||
+ (NSString *)skuToken {
|
||||
return @"foo";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface MGLAccountManagerTests : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation MGLAccountManagerTests
|
||||
|
||||
- (void)testSKU {
|
||||
XCTAssertTrue([[MGLAccountManager valueForKeyPath:@"skuToken"] isEqualToString:@"foo"]);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user