From d5132e4f914f6dff0dba7cd780a49a0f0d7eebba Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Fri, 2 Aug 2024 11:16:03 -0700 Subject: [PATCH] Added param in function initUserSessionAndCallCallback for forced session re-initialization irrespective of current SDK initializationStatus --- Sources/BranchSDK/Branch.m | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 7619d0186..ab9580555 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -526,7 +526,7 @@ + (void)setTrackingDisabled:(BOOL)disabled { // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: - [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil]; + [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil reset:NO]; } } } @@ -642,7 +642,7 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options } #endif - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL reset:NO]; } - (void)setDeepLinkDebugMode:(NSDictionary *)debugParams { @@ -693,7 +693,7 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier self.preferenceHelper.externalIntentURI = pattern; self.preferenceHelper.referringURL = pattern; - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil reset:YES]; return NO; } @@ -741,7 +741,7 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce self.preferenceHelper.linkClickIdentifier = params[@"link_click_id"]; } } - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:url.absoluteString]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:url.absoluteString reset:YES]; return handled; } @@ -775,7 +775,7 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil]; } - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString reset:YES]; return [Branch isBranchLink:urlString]; } @@ -815,7 +815,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS } #endif - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:userActivity.webpageURL.absoluteString]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:userActivity.webpageURL.absoluteString reset:YES]; return spotlightIdentifier != nil; } @@ -1716,7 +1716,7 @@ - (void)applicationDidBecomeActive { if (!Branch.trackingDisabled && self.initializationStatus != BNCInitStatusInitialized && !installOrOpenInQueue) { [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"applicationDidBecomeActive trackingDisabled %d initializationStatus %d installOrOpenInQueue %d", Branch.trackingDisabled, self.initializationStatus, installOrOpenInQueue] error:nil]; - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil reset:NO]; } }); } @@ -1889,6 +1889,7 @@ - (void)processNextQueueItem { if ( !(((BNCServerRequestQueue*)[BNCServerRequestQueue getInstance]).processArchivedOpens) && [req isKindOfClass:[BranchOpenRequest class]] && ((BranchOpenRequest *)req).isFromArchivedQueue){ + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Removed Archived Open Request from Queue %@", [req description]] error:nil]; [self.requestQueue remove:req]; self.networkCount = 0; [self processNextQueueItem]; @@ -1954,11 +1955,11 @@ - (void)notifyNativeToInit { - (void)initSafetyCheck { if (self.initializationStatus == BNCInitStatusUninitialized) { [[BranchLogger shared] logDebug:@"Branch avoided an error by preemptively initializing." error:nil]; - [self initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil]; + [self initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil reset:NO]; } } -- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString { +- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString reset:(BOOL)reset { @synchronized (self) { if (self.deferInitForPluginRuntime) { @@ -1980,8 +1981,9 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr dispatch_async(self.isolationQueue, ^(){ + // If the session is not yet initialized - if (self.initializationStatus == BNCInitStatusUninitialized) { + if ( reset || self.initializationStatus == BNCInitStatusUninitialized) { [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier urlString:urlString]; } // If the session was initialized, but callCallback was specified, do so.