diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m index 2eb3cb282..a54dbad02 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCSystemObserverTests.m @@ -9,6 +9,10 @@ #import #import "BNCSystemObserver.h" +@interface BNCSystemObserver () ++ (BOOL)compareUriSchemes:(NSString *)serverUriScheme With:(NSArray *)urlTypes; +@end + @interface BNCSystemObserverTests : XCTestCase @end @@ -100,4 +104,35 @@ - (void)testIsAppClip { XCTAssert(![BNCSystemObserver isAppClip]); } +- (void)testCompareURIScemes { + + NSString *serverUriScheme = @"bnctest://"; + NSArray *urlTypes = @[@{@"CFBundleURLSchemes" : @[@""]}, @{@"CFBundleURLSchemes" : @[@"bnctest", @"xyzs"]}]; + + XCTAssertTrue([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]); + + XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:nil]); + + XCTAssertFalse([BNCSystemObserver compareUriSchemes:nil With:nil]); + + XCTAssertFalse([BNCSystemObserver compareUriSchemes:nil With:urlTypes]); + + serverUriScheme = @":/"; + XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]); + + serverUriScheme = @"bnctest"; + XCTAssertTrue([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]); + + serverUriScheme = @"bnctest://"; + urlTypes = @[ @{@"CFBundleURLSchemes" : @[@"bnctestX", @"xyzs"]}]; + XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]); + + serverUriScheme = @"://"; + XCTAssertFalse([BNCSystemObserver compareUriSchemes:serverUriScheme With:urlTypes]); + + XCTAssertFalse([BNCSystemObserver compareUriSchemes:@"" With:urlTypes]); + + XCTAssertFalse([BNCSystemObserver compareUriSchemes:@"" With:@[@{}]]); +} + @end diff --git a/Sources/BranchSDK/BNCSystemObserver.m b/Sources/BranchSDK/BNCSystemObserver.m index 600e88922..ca8636269 100644 --- a/Sources/BranchSDK/BNCSystemObserver.m +++ b/Sources/BranchSDK/BNCSystemObserver.m @@ -150,14 +150,25 @@ + (NSString *)defaultURIScheme { + (BOOL)compareUriSchemes : (NSString *) serverUriScheme { NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"]; + return [self compareUriSchemes:serverUriScheme With:urlTypes]; +} + ++ (BOOL)compareUriSchemes:(NSString *)serverUriScheme With:(NSArray *)urlTypes { + NSString * serverUriSchemeWithoutSuffix ; + + if ([serverUriScheme hasSuffix:@"://"]) { + serverUriSchemeWithoutSuffix = [serverUriScheme substringToIndex:[serverUriScheme length] - 3]; + } else { + serverUriSchemeWithoutSuffix = serverUriScheme; + } for (NSDictionary *urlType in urlTypes) { NSArray *urlSchemes = [urlType objectForKey:@"CFBundleURLSchemes"]; for (NSString *uriScheme in urlSchemes) { - NSString * serverUriSchemeWithoutSuffix = [serverUriScheme substringToIndex:[serverUriScheme length] - 3]; if ([uriScheme isEqualToString:serverUriSchemeWithoutSuffix]) { - return true; } + return true; + } } } return false;