From 6b1270bb842e449f43de698013e801535a0c8f49 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 26 Mar 2024 18:03:25 -0700 Subject: [PATCH 1/4] SDK-2309 cache link data when initialization is deferred for plugins --- Sources/BranchSDK/Branch.m | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 984fbb40d..ed23381f4 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -155,6 +155,7 @@ @interface Branch() { // This is enabled by setting deferInitForPluginRuntime to true in branch.json @property (nonatomic, assign, readwrite) BOOL deferInitForPluginRuntime; @property (nonatomic, copy, nullable) void (^cachedInitBlock)(void); +@property (nonatomic, copy, readwrite) NSString *cachedURLString; @end @@ -1922,11 +1923,21 @@ - (void)initSafetyCheck { - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString { - // ignore lifecycle calls while waiting for a plugin runtime. @synchronized (self) { if (self.deferInitForPluginRuntime) { - [[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring init call."]; + if (urlString) { + [[BranchLogger shared] logDebug:@"Branch init is deferred, caching link"]; + self.cachedURLString = urlString; + } else { + [[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring lifecycle call without a link"]; + } return; + } else { + if (!urlString && self.cachedURLString) { + urlString = self.cachedURLString; + self.cachedURLString = nil; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", urlString]]; + } } } From 7b2b5dbb2c4543f9ff384746eb0131c4c91f03bb Mon Sep 17 00:00:00 2001 From: echo Date: Wed, 27 Mar 2024 15:20:34 -0700 Subject: [PATCH 2/4] always clear the cached link, if there's another link coming in it takes priority anyway --- Sources/BranchSDK/Branch.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index ed23381f4..5a621f435 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -1935,9 +1935,9 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr } else { if (!urlString && self.cachedURLString) { urlString = self.cachedURLString; - self.cachedURLString = nil; [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", urlString]]; } + self.cachedURLString = nil; } } From b30349c6433bceb94a1639d0017b6adde5534fa5 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 2 Apr 2024 11:58:18 -0700 Subject: [PATCH 3/4] Fix logger messages after merge with main --- Sources/BranchSDK/Branch.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index fd8865768..7ef5adaaa 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -1942,16 +1942,16 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr @synchronized (self) { if (self.deferInitForPluginRuntime) { if (urlString) { - [[BranchLogger shared] logDebug:@"Branch init is deferred, caching link"]; + [[BranchLogger shared] logDebug:@"Branch init is deferred, caching link" error:nil]; self.cachedURLString = urlString; } else { - [[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring lifecycle call without a link"]; + [[BranchLogger shared] logDebug:@"Branch init is deferred, ignoring lifecycle call without a link" error:nil]; } return; } else { if (!urlString && self.cachedURLString) { urlString = self.cachedURLString; - [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", urlString]]; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", urlString] error:nil]; } self.cachedURLString = nil; } From 2009c84ae1b603d963a5e064c2f5eb7e97f6f242 Mon Sep 17 00:00:00 2001 From: echo Date: Tue, 2 Apr 2024 14:30:36 -0700 Subject: [PATCH 4/4] Allow init calls to come in late. --- Sources/BranchSDK/Branch.m | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 7ef5adaaa..fc6484cfd 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -625,27 +625,20 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options [self.class addBranchSDKVersionToCrashlyticsReport]; self.shouldAutomaticallyDeepLink = automaticallyDisplayController; - // If the SDK is already initialized, this means that initSession was called after other lifecycle calls. - if (self.initializationStatus == BNCInitStatusInitialized) { - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; - return; - } - - // Save data from push notification on app launch + // Check for Branch link in a push payload + NSString *pushURL = nil; #if !TARGET_OS_TV if ([options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { id branchUrlFromPush = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY]; if ([branchUrlFromPush isKindOfClass:[NSString class]]) { self.preferenceHelper.universalLinkUrl = branchUrlFromPush; self.preferenceHelper.referringURL = branchUrlFromPush; + pushURL = (NSString *)branchUrlFromPush; } } #endif - // Handle case where there's no URI scheme or Universal Link. - if (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) { - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; - } + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL]; } - (void)setDeepLinkDebugMode:(NSDictionary *)debugParams {