From 56c92ff37c5da9c20435f8da1fe114d5044fb826 Mon Sep 17 00:00:00 2001 From: Rob Gioia Date: Mon, 23 Oct 2023 10:04:07 -0400 Subject: [PATCH] Looped through each of the URI schemes so that Branch doesn't have to be the first URI scheme in the list for the integration validator to pass Looped through each of the URI schemes so that Branch doesn't have to be the first URI scheme in the list for the integration validator to pass --- BranchSDK/BNCSystemObserver.h | 1 + BranchSDK/BNCSystemObserver.m | 17 +++++++++++++++++ BranchSDK/Branch+Validator.m | 11 ++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/BranchSDK/BNCSystemObserver.h b/BranchSDK/BNCSystemObserver.h index 24899a6a4..9b8119027 100644 --- a/BranchSDK/BNCSystemObserver.h +++ b/BranchSDK/BNCSystemObserver.h @@ -33,5 +33,6 @@ + (NSString *)appleAttributionToken; + (NSString *)environment; + (BOOL)isAppClip; ++ (BOOL)compareUriSchemes:(NSString *) serverUriScheme; @end diff --git a/BranchSDK/BNCSystemObserver.m b/BranchSDK/BNCSystemObserver.m index cc4944302..9b11dcd4e 100644 --- a/BranchSDK/BNCSystemObserver.m +++ b/BranchSDK/BNCSystemObserver.m @@ -142,6 +142,23 @@ + (NSString *)defaultURIScheme { return nil; } ++ (BOOL)compareUriSchemes : (NSString *) serverUriScheme { + NSArray *urlTypes = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleURLTypes"]; + + 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; } + } + // If no Uri schemes match the one set on the dashboard + return false; + } + return false; +} + + (NSString *)bundleIdentifier { return [[NSBundle mainBundle] bundleIdentifier]; } diff --git a/BranchSDK/Branch+Validator.m b/BranchSDK/Branch+Validator.m index 5deca2670..8a387a803 100644 --- a/BranchSDK/Branch+Validator.m +++ b/BranchSDK/Branch+Validator.m @@ -69,16 +69,13 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response { NSLog(@"------ Checking for URI scheme correctness ------"); NSString *clientUriScheme = [NSString stringWithFormat:@"%@%@", [BNCSystemObserver defaultURIScheme], @"://"]; - NSString *uriScheme = [serverUriScheme isEqualToString:clientUriScheme] ? passString : errorString; - NSString *uriSchemeMessage = - [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", - uriScheme, serverUriScheme, clientUriScheme]; - NSLog(@"%@",uriSchemeMessage); + NSString *uriScheme = [BNCSystemObserver compareUriSchemes:serverUriScheme] ? passString : errorString; NSLog(@"-------------------------------------------------"); NSLog(@"-- Checking for bundle identifier correctness ---"); NSString *clientBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier] ?: @""; - NSString *bundleIdentifier = [serverBundleID isEqualToString:clientBundleIdentifier] ? passString : errorString; + bool doUriSchemesMatch = [serverBundleID isEqualToString:clientBundleIdentifier]; + NSString *bundleIdentifier = doUriSchemesMatch ? passString : errorString; NSString *bundleIdentifierMessage = [NSString stringWithFormat:@"%@: Dashboard Link Settings page '%@' compared to client side '%@'", bundleIdentifier, serverBundleID, clientBundleIdentifier]; @@ -113,7 +110,7 @@ - (void) validateIntegrationWithServerResponse:(BNCServerResponse*)response { // Build an alert string: NSString *alertString = @"\n"; - if (serverUriScheme.length && [serverUriScheme isEqualToString:clientUriScheme]) { + if (serverUriScheme.length && doUriSchemesMatch) { alertString = [alertString stringByAppendingFormat:@"%@URI Scheme matches:\n\t'%@'\n", kPassMark, serverUriScheme]; } else {