diff options
author | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2019-06-10 15:08:00 +0200 |
---|---|---|
committer | Fredrik Karlsson <bjorn.fredrik.karlsson@gmail.com> | 2019-06-11 18:35:07 +0200 |
commit | ad1b448da5079e38db8b6bb8eb565677b0f6a225 (patch) | |
tree | d7ecc118aae9524cc417b241c660c2609d37900d | |
parent | 685a9e5e94627e9ffc914b2955533c6ceeb62644 (diff) | |
download | qtlocation-mapboxgl-ad1b448da5079e38db8b6bb8eb565677b0f6a225.tar.gz |
[ios] get sku token return value
-rw-r--r-- | platform/darwin/src/MGLAccountManager.m | 25 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | platform/ios/test/MGLAccountManagerTests.m | 25 |
3 files changed, 35 insertions, 19 deletions
diff --git a/platform/darwin/src/MGLAccountManager.m b/platform/darwin/src/MGLAccountManager.m index 48750e1d49..69170459bc 100644 --- a/platform/darwin/src/MGLAccountManager.m +++ b/platform/darwin/src/MGLAccountManager.m @@ -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 diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 44e6499f31..be7d0e4249 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -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 */, diff --git a/platform/ios/test/MGLAccountManagerTests.m b/platform/ios/test/MGLAccountManagerTests.m new file mode 100644 index 0000000000..fd59de2fd5 --- /dev/null +++ b/platform/ios/test/MGLAccountManagerTests.m @@ -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 |