From cfcd2aa393f803302f9b50c76ba1558e4bdd7928 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:45:58 -0800 Subject: [PATCH 01/10] Remove variable _isFromArchivedQueue which was used for caching, which is already removed. --- Sources/BranchSDK/BNCServerRequestQueue.m | 2 +- Sources/BranchSDK/BranchOpenRequest.m | 1 - Sources/BranchSDK/Private/BranchOpenRequest.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/BranchSDK/BNCServerRequestQueue.m b/Sources/BranchSDK/BNCServerRequestQueue.m index c518fccce..84f69f20e 100755 --- a/Sources/BranchSDK/BNCServerRequestQueue.m +++ b/Sources/BranchSDK/BNCServerRequestQueue.m @@ -138,7 +138,7 @@ - (BranchOpenRequest *)findExistingInstallOrOpen { // Install subclasses open, so only need to check open // Request should not be the one added from archived queue - if ([request isKindOfClass:[BranchOpenRequest class]] && !((BranchOpenRequest *)request).isFromArchivedQueue) { + if ([request isKindOfClass:[BranchOpenRequest class]]) { return (BranchOpenRequest *)request; } } diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index 9bd10f806..15ea316e8 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -40,7 +40,6 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall { if ((self = [super init])) { _callback = callback; _isInstall = isInstall; - _isFromArchivedQueue = NO; } return self; diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index ec5717cd6..978496190 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -13,7 +13,6 @@ // URL that triggered this install or open event @property (nonatomic, copy, readwrite) NSString *urlString; -@property (assign, nonatomic) BOOL isFromArchivedQueue; @property (nonatomic, copy) callbackWithStatus callback; + (void) waitForOpenResponseLock; From f5263ed2770559a900b0b8ec7f59372a500d1e5e Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:21:17 -0800 Subject: [PATCH 02/10] Initial Refactor Commit --- .../BNCPreferenceHelperTests.m | 6 -- Sources/BranchSDK/BNCAppGroupsData.m | 4 +- Sources/BranchSDK/BNCPreferenceHelper.m | 94 ------------------- Sources/BranchSDK/BNCRequestFactory.m | 33 ++++--- Sources/BranchSDK/Branch.m | 93 +++++++++--------- Sources/BranchSDK/BranchInstallRequest.m | 2 +- Sources/BranchSDK/BranchOpenRequest.m | 28 +++--- Sources/BranchSDK/Private/BNCRequestFactory.h | 6 +- Sources/BranchSDK/Private/BranchOpenRequest.h | 10 ++ .../BranchSDK/Public/BNCPreferenceHelper.h | 7 -- 10 files changed, 101 insertions(+), 182 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m index 5269501b3..be4b97294 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m @@ -364,14 +364,8 @@ - (void)testClearTrackingInformation { [self.prefHelper clearTrackingInformation]; XCTAssertNil(self.prefHelper.sessionID); - XCTAssertNil(self.prefHelper.linkClickIdentifier); - XCTAssertNil(self.prefHelper.spotlightIdentifier); - XCTAssertNil(self.prefHelper.referringURL); - XCTAssertNil(self.prefHelper.universalLinkUrl); - XCTAssertNil(self.prefHelper.initialReferrer); XCTAssertNil(self.prefHelper.installParams); XCTAssertNil(self.prefHelper.sessionParams); - XCTAssertNil(self.prefHelper.externalIntentURI); XCTAssertNil(self.prefHelper.savedAnalyticsData); XCTAssertNil(self.prefHelper.previousAppBuildDate); XCTAssertEqual(self.prefHelper.requestMetadataDictionary.count, 0); diff --git a/Sources/BranchSDK/BNCAppGroupsData.m b/Sources/BranchSDK/BNCAppGroupsData.m index cb4908f86..f36420342 100644 --- a/Sources/BranchSDK/BNCAppGroupsData.m +++ b/Sources/BranchSDK/BNCAppGroupsData.m @@ -64,7 +64,7 @@ - (NSDate *)getDateForKey:(NSString *)key { return nil; } -- (void)saveAppClipData { +- (void)saveAppClipData:(NSString *) referringURL { if ([BNCSystemObserver isAppClip]) { BNCApplication *application = [BNCApplication currentApplication]; @@ -79,7 +79,7 @@ - (void)saveAppClipData { BNCPreferenceHelper *preferenceHelper = [BNCPreferenceHelper sharedInstance]; - NSString *url = preferenceHelper.referringURL; + NSString *url = referringURL; NSString *token = preferenceHelper.randomizedDeviceToken; NSString *bundleToken = preferenceHelper.randomizedBundleToken; diff --git a/Sources/BranchSDK/BNCPreferenceHelper.m b/Sources/BranchSDK/BNCPreferenceHelper.m index 1acf209a0..7087257fa 100644 --- a/Sources/BranchSDK/BNCPreferenceHelper.m +++ b/Sources/BranchSDK/BNCPreferenceHelper.m @@ -73,7 +73,6 @@ @interface BNCPreferenceHelper () { NSOperationQueue *_persistPrefsQueue; NSString *_lastSystemBuildVersion; NSString *_browserUserAgentString; - NSString *_referringURL; } @property (strong, nonatomic) NSMutableDictionary *persistenceDict; @@ -90,20 +89,15 @@ @implementation BNCPreferenceHelper // since we override both setter and getter, these properties do not auto synthesize @synthesize lastRunBranchKey = _lastRunBranchKey, - appVersion = _appVersion, randomizedDeviceToken = _randomizedDeviceToken, sessionID = _sessionID, - spotlightIdentifier = _spotlightIdentifier, randomizedBundleToken = _randomizedBundleToken, - linkClickIdentifier = _linkClickIdentifier, userUrl = _userUrl, userIdentity = _userIdentity, sessionParams = _sessionParams, installParams = _installParams, - universalLinkUrl = _universalLinkUrl, initialReferrer = _initialReferrer, localUrl = _localUrl, - externalIntentURI = _externalIntentURI, isDebug = _isDebug, retryCount = _retryCount, retryInterval = _retryInterval, @@ -220,20 +214,6 @@ - (void)setLastStrongMatchDate:(NSDate *)lastStrongMatchDate { } } -- (NSString *)appVersion { - if (!_appVersion) { - _appVersion = [self readStringFromDefaults:BRANCH_PREFS_KEY_APP_VERSION]; - } - return _appVersion; -} - -- (void)setAppVersion:(NSString *)appVersion { - if (![_appVersion isEqualToString:appVersion]) { - _appVersion = appVersion; - [self writeObjectToDefaults:BRANCH_PREFS_KEY_APP_VERSION value:appVersion]; - } -} - - (NSString *)randomizedDeviceToken { if (!_randomizedDeviceToken) { NSString *tmp = [self readStringFromDefaults:BRANCH_PREFS_KEY_RANDOMIZED_DEVICE_TOKEN]; @@ -308,62 +288,6 @@ - (void)setUserIdentity:(NSString *)userIdentity { [self writeObjectToDefaults:BRANCH_PREFS_KEY_IDENTITY value:userIdentity]; } -- (NSString *)linkClickIdentifier { - return [self readStringFromDefaults:BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER]; -} - -- (void)setLinkClickIdentifier:(NSString *)linkClickIdentifier { - [self writeObjectToDefaults:BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER value:linkClickIdentifier]; -} - -- (NSString *)spotlightIdentifier { - return [self readStringFromDefaults:BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER]; -} - -- (void)setSpotlightIdentifier:(NSString *)spotlightIdentifier { - [self writeObjectToDefaults:BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER value:spotlightIdentifier]; -} - -- (NSString *)externalIntentURI { - @synchronized(self) { - if (!_externalIntentURI) { - _externalIntentURI = [self readStringFromDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI]; - } - return _externalIntentURI; - } -} - -- (void)setExternalIntentURI:(NSString *)externalIntentURI { - @synchronized(self) { - if (externalIntentURI == nil || ![_externalIntentURI isEqualToString:externalIntentURI]) { - _externalIntentURI = externalIntentURI; - [self writeObjectToDefaults:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI value:externalIntentURI]; - } - } -} - -- (NSString*) referringURL { - @synchronized (self) { - if (!_referringURL) _referringURL = [self readStringFromDefaults:@"referringURL"]; - return _referringURL; - } -} - -- (void) setReferringURL:(NSString *)referringURL { - @synchronized (self) { - _referringURL = [referringURL copy]; - [self writeObjectToDefaults:@"referringURL" value:_referringURL]; - } -} - -- (NSString *)universalLinkUrl { - return [self readStringFromDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL]; -} - -- (void)setUniversalLinkUrl:(NSString *)universalLinkUrl { - [self writeObjectToDefaults:BRANCH_PREFS_KEY_UNIVERSAL_LINK_URL value:universalLinkUrl]; -} - - (NSString *)localUrl { return [self readStringFromDefaults:BRANCH_PREFS_KEY_LOCAL_URL]; } @@ -618,18 +542,6 @@ - (void) setSavedURLPatternListVersion:(NSInteger)URLPatternListVersion { } } -- (BOOL) dropURLOpen { - @synchronized(self) { - return [self readBoolFromDefaults:@"dropURLOpen"]; - } -} - -- (void) setDropURLOpen:(BOOL)value { - @synchronized(self) { - [self writeBoolToDefaults:@"dropURLOpen" value:value]; - } -} - - (BOOL) trackingDisabled { @synchronized(self) { NSNumber *b = (id) [self readObjectFromDefaults:@"trackingDisabled"]; @@ -849,14 +761,8 @@ - (void) clearTrackingInformation { self.randomizedBundleToken = nil; */ self.sessionID = nil; - self.linkClickIdentifier = nil; - self.spotlightIdentifier = nil; - self.referringURL = nil; - self.universalLinkUrl = nil; - self.initialReferrer = nil; self.installParams = nil; self.sessionParams = nil; - self.externalIntentURI = nil; self.savedAnalyticsData = nil; self.previousAppBuildDate = nil; self.requestMetadataDictionary = nil; diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 660152714..26c5a824e 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -34,6 +34,8 @@ #import "BNCSKAdNetwork.h" #import "BNCReferringURLUtility.h" #import "BNCPasteboard.h" +#import "BranchOpenRequest.h" +#import "BranchInstallRequest.h" @interface BNCRequestFactory() @@ -80,7 +82,7 @@ - (BOOL)isTrackingDisabled { return Branch.trackingDisabled; } -- (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString { +- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest { NSMutableDictionary *json = [NSMutableDictionary new]; // All requests @@ -99,13 +101,13 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString { // Install and Open [self addDeveloperUserIDToJSON:json]; [self addSystemObserverDataToJSON:json]; - [self addPreferenceHelperDataToJSON:json]; + [self addOpenRequestDataToJSON:json fromRequestObject:installRequest]; [self addPartnerParametersToJSON:json]; [self addAppleReceiptSourceToJSON:json]; [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (urlString) { + /* if (openRequest.) { NSURL *url = [NSURL URLWithString:urlString]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; @@ -113,7 +115,7 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString { [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } } - + */ [self addAppleAttributionTokenToJSON:json]; // Install Only @@ -132,7 +134,7 @@ - (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString { return json; } -- (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString { +- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest { NSMutableDictionary *json = [NSMutableDictionary new]; // All requests @@ -154,19 +156,19 @@ - (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString { // Install and Open [self addDeveloperUserIDToJSON:json]; [self addSystemObserverDataToJSON:json]; - [self addPreferenceHelperDataToJSON:json]; + [self addOpenRequestDataToJSON:json fromRequestObject:openRequest]; [self addPartnerParametersToJSON:json]; [self addAppleReceiptSourceToJSON:json]; [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (urlString) { - NSURL *url = [NSURL URLWithString:urlString]; + if (openRequest.urlString) { + NSURL *url = [NSURL URLWithString:openRequest.urlString]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { - [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; + [self safeSetValue:openRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; } else { - [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; + [self safeSetValue:openRequest.urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } } @@ -303,15 +305,16 @@ - (void)addShortURLTokensToJSON:(NSMutableDictionary *)json isSpotlightRequest:( json[BRANCH_REQUEST_KEY_SESSION_ID] = self.preferenceHelper.sessionID; } -- (void)addPreferenceHelperDataToJSON:(NSMutableDictionary *)json { +- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromRequestObject:(BranchOpenRequest *) openRequest{ json[BRANCH_REQUEST_KEY_DEBUG] = @(self.preferenceHelper.isDebug); - - [self safeSetValue:self.preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json]; - [self safeSetValue:self.preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json]; [self safeSetValue:self.preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:json]; + [self safeSetValue:openRequest.linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json]; + [self safeSetValue:openRequest.linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json]; + + // This was only on opens before, cause it can't exist on install. - [self safeSetValue:self.preferenceHelper.externalIntentURI forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; + [self safeSetValue:openRequest.linkParams.externalIntentURI forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } - (void)addSystemObserverDataToJSON:(NSMutableDictionary *)json { diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index f1178f45c..21baf2fcc 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -533,7 +533,7 @@ + (void)setTrackingDisabled:(BOOL)disabled { // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: - [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil reset:NO]; + [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil urlParams:nil reset:NO]; } } } @@ -582,7 +582,7 @@ - (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: - [[Branch getInstance] initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil reset:true]; + [[Branch getInstance] initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil urlParams:nil reset:true]; } } @@ -682,19 +682,20 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options // Check for Branch link in a push payload NSString *pushURL = nil; + BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; #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; + params.universalLinkUrl = branchUrlFromPush; + params.referringURL = branchUrlFromPush; pushURL = (NSString *)branchUrlFromPush; } } #endif if(pushURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) { - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL reset:NO]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL urlParams:params reset:NO]; } } @@ -741,14 +742,17 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier if (!pattern) { pattern = [self.userURLFilter patternMatchingURL:url]; } + + BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; if (pattern) { - self.preferenceHelper.dropURLOpen = YES; + params.dropURLOpen = YES; NSString *urlString = [url absoluteString]; - self.preferenceHelper.externalIntentURI = urlString; - self.preferenceHelper.referringURL = urlString; + params.externalIntentURI = urlString; + params.referringURL = urlString; - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil urlParams:params reset:YES]; + return NO; } @@ -762,8 +766,7 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sceneIdentifier { BOOL handled = NO; - self.preferenceHelper.referringURL = nil; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set referringURL to %@", self.preferenceHelper.referringURL] error:nil]; + BranchOpenRequestLinkParams *openRequestParams = [[BranchOpenRequestLinkParams alloc] init]; if (url && ![url isEqual:[NSNull null]]) { @@ -773,15 +776,15 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce if ([self.allowedSchemeList count]) { for (NSString *scheme in self.allowedSchemeList) { if (urlScheme && [scheme isEqualToString:urlScheme]) { - self.preferenceHelper.externalIntentURI = [url absoluteString]; - self.preferenceHelper.referringURL = [url absoluteString]; + openRequestParams.externalIntentURI = [url absoluteString]; + openRequestParams.referringURL = [url absoluteString]; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; break; } } } else { - self.preferenceHelper.externalIntentURI = [url absoluteString]; - self.preferenceHelper.referringURL = [url absoluteString]; + openRequestParams.externalIntentURI = [url absoluteString]; + openRequestParams.referringURL = [url absoluteString]; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; } @@ -793,10 +796,10 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce NSDictionary *params = [BNCEncodingUtils decodeQueryStringToDictionary:query]; if (params[@"link_click_id"]) { handled = YES; - self.preferenceHelper.linkClickIdentifier = params[@"link_click_id"]; + openRequestParams.linkClickIdentifier = params[@"link_click_id"]; } } - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:url.absoluteString reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:url.absoluteString urlParams:openRequestParams reset:YES]; return handled; } @@ -805,7 +808,7 @@ - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { - return [self handleDeepLink:url sceneIdentifier:nil]; + return [self handleDeepLink:url sceneIdentifier:nil ]; } - (BOOL)sceneIdentifier:(NSString *)sceneIdentifier @@ -824,13 +827,15 @@ - (BOOL)application:(UIApplication *)application } - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NSString *)sceneIdentifier { + + BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; if (urlString.length) { - self.preferenceHelper.universalLinkUrl = urlString; - self.preferenceHelper.referringURL = urlString; + params.universalLinkUrl = urlString; + params.referringURL = urlString; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil]; } - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:urlString urlParams:params reset:YES]; return [Branch isBranchLink:urlString]; } @@ -850,7 +855,8 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS } NSString *spotlightIdentifier = nil; - + BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; + #if !TARGET_OS_TV // Check to see if a spotlight activity needs to be handled spotlightIdentifier = [self.contentDiscoveryManager spotlightIdentifierFromActivity:userActivity]; @@ -861,16 +867,16 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS } else if (webURL != nil && [Branch isBranchLink:[webURL absoluteString]]) { return [self handleDeepLink:webURL sceneIdentifier:sceneIdentifier]; } else if (spotlightIdentifier) { - self.preferenceHelper.spotlightIdentifier = spotlightIdentifier; + params.spotlightIdentifier = spotlightIdentifier; } else { NSString *nonBranchSpotlightIdentifier = [self.contentDiscoveryManager standardSpotlightIdentifierFromActivity:userActivity]; if (nonBranchSpotlightIdentifier) { - self.preferenceHelper.spotlightIdentifier = nonBranchSpotlightIdentifier; + params.spotlightIdentifier = nonBranchSpotlightIdentifier; } } #endif - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:userActivity.webpageURL.absoluteString reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:userActivity.webpageURL.absoluteString urlParams:params reset:YES]; return spotlightIdentifier != nil; } @@ -1494,7 +1500,6 @@ + (Branch *)getInstanceInternal:(NSString *)key { // Note: Link Click Identifier is not cleared because of the potential for that to mess up a deep link if (preferenceHelper.lastRunBranchKey && ![key isEqualToString:preferenceHelper.lastRunBranchKey]) { [[BranchLogger shared] logWarning:@"The Branch Key has changed, clearing relevant items." error:nil]; - preferenceHelper.appVersion = nil; preferenceHelper.randomizedDeviceToken = nil; preferenceHelper.sessionID = nil; preferenceHelper.randomizedBundleToken = nil; @@ -1771,7 +1776,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 reset:NO]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:nil urlParams:nil reset:NO]; } }); } @@ -1998,11 +2003,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 reset:NO]; + [self initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil urlParams:nil reset:NO]; } } -- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString reset:(BOOL)reset { +- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString urlParams:(BranchOpenRequestLinkParams *)params reset:(BOOL)reset { @synchronized (self) { if (self.deferInitForPluginRuntime) { @@ -2028,7 +2033,7 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr // If the session is not yet initialized OR // If the session is already initialized or is initializing but we need to reset it. if ( reset || self.initializationStatus == BNCInitStatusUninitialized) { - [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier urlString:urlString]; + [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier urlString:urlString urlParams:params]; } // If the session was initialized, but callCallback was specified, do so. else if (callCallback && self.initializationStatus == BNCInitStatusInitialized) { @@ -2049,10 +2054,10 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr } // only called from initUserSessionAndCallCallback! -- (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString { +- (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString urlParams:(BranchOpenRequestLinkParams *)params { // BranchDelegate willStartSessionWithURL notification - NSURL *URL = (self.preferenceHelper.referringURL.length) ? [NSURL URLWithString:self.preferenceHelper.referringURL] : nil; + NSURL *URL = (params.referringURL.length) ? [NSURL URLWithString:params.referringURL] : nil; if ([self.delegate respondsToSelector:@selector(branch:willStartSessionWithURL:)]) { [self.delegate branch:self willStartSessionWithURL:URL]; } @@ -2067,9 +2072,9 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS // callback on main, this is generally what the client expects and maintains our previous behavior dispatch_async(dispatch_get_main_queue(), ^ { if (error) { - [self handleInitFailure:error callCallback:callCallback sceneIdentifier:(NSString *)sceneIdentifier]; + [self handleInitFailure:error callCallback:callCallback sceneIdentifier:(NSString *)sceneIdentifier referringURL:params.referringURL]; } else { - [self handleInitSuccessAndCallCallback:callCallback sceneIdentifier:(NSString *)sceneIdentifier]; + [self handleInitSuccessAndCallCallback:callCallback sceneIdentifier:(NSString *)sceneIdentifier referringURL:params.referringURL]; } }); }; @@ -2088,6 +2093,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } req.callback = initSessionCallback; req.urlString = urlString; + req.linkParams = params [self.requestQueue insert:req at:0]; @@ -2101,6 +2107,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS req = [[BranchOpenRequest alloc] initWithCallback:initSessionCallback]; req.callback = initSessionCallback; req.urlString = urlString; + req.linkParams = params; // put it behind the one that's already on queue [self.requestQueue insert:req at:1]; @@ -2120,7 +2127,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } -- (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier { +- (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier referringURL:(NSString *) referringURL{ self.initializationStatus = BNCInitStatusInitialized; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil]; @@ -2152,7 +2159,7 @@ - (void)handleInitSuccessAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS self.sceneSessionInitWithCallback(response, nil); } } - [self sendOpenNotificationWithLinkParameters:latestReferringParams error:nil]; + [self sendOpenNotificationWithLinkParameters:latestReferringParams referringURL:referringURL error:nil]; [self.urlFilter updatePatternListFromServerWithCompletion:nil]; @@ -2269,12 +2276,12 @@ - (void)automaticallyDeeplinkWithReferringParams:(NSDictionary *)latestReferring } } -- (void)sendOpenNotificationWithLinkParameters:(NSDictionary*)linkParameters +- (void)sendOpenNotificationWithLinkParameters:(NSDictionary*)linkParameters referringURL:(NSString *) referringURL error:(NSError*)error { - NSURL *originalURL = - (self.preferenceHelper.referringURL.length) - ? [NSURL URLWithString:self.preferenceHelper.referringURL] + NSURL *originalURL = + (referringURL.length) + ? [NSURL URLWithString:referringURL] : nil; BranchLinkProperties *linkProperties = nil; BranchUniversalObject *universalObject = nil; @@ -2310,8 +2317,6 @@ - (void)sendOpenNotificationWithLinkParameters:(NSDictionary*)linkParameters postNotificationName:BranchDidStartSessionNotification object:self userInfo:userInfo]; - - self.preferenceHelper.referringURL = nil; } - (void)removeViewControllerFromRootNavigationController:(UIViewController*)branchSharingController { @@ -2339,7 +2344,7 @@ - (void)presentSharingViewController:(UIViewController +#import "BranchOpenRequest.h" +#import "BranchInstallRequest.h" NS_ASSUME_NONNULL_BEGIN @@ -23,8 +25,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithBranchKey:(NSString *)key UUID:(NSString *)requestUUID TimeStamp:(NSNumber *)requestTimeStamp NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; -- (NSDictionary *)dataForInstallWithURLString:(nullable NSString *)urlString; -- (NSDictionary *)dataForOpenWithURLString:(nullable NSString *)urlString; +- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest; +- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest; // Event data is passed in - (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)dictionary; diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index 978496190..cd348520b 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -9,11 +9,21 @@ #import "BNCServerRequest.h" #import "BNCCallbacks.h" +@interface BranchOpenRequestLinkParams : NSObject +@property (copy, nonatomic) NSString *linkClickIdentifier; +@property (copy, nonatomic) NSString *spotlightIdentifier; +@property (copy, nonatomic) NSString *universalLinkUrl; +@property (copy, nonatomic) NSString *referringURL; +@property (copy, nonatomic) NSString *externalIntentURI; +@property (assign, nonatomic) BOOL dropURLOpen; +@end + @interface BranchOpenRequest : BNCServerRequest // URL that triggered this install or open event @property (nonatomic, copy, readwrite) NSString *urlString; @property (nonatomic, copy) callbackWithStatus callback; +@property (nonatomic, copy, readwrite) BranchOpenRequestLinkParams *linkParams; + (void) waitForOpenResponseLock; + (void) releaseOpenResponseLock; diff --git a/Sources/BranchSDK/Public/BNCPreferenceHelper.h b/Sources/BranchSDK/Public/BNCPreferenceHelper.h index 464d5508a..0265670b8 100644 --- a/Sources/BranchSDK/Public/BNCPreferenceHelper.h +++ b/Sources/BranchSDK/Public/BNCPreferenceHelper.h @@ -23,16 +23,12 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (copy, nonatomic) NSString *lastRunBranchKey; @property (strong, nonatomic) NSDate *lastStrongMatchDate; -@property (copy, nonatomic) NSString *appVersion; @property (copy, nonatomic) NSString *randomizedDeviceToken; @property (copy, nonatomic) NSString *randomizedBundleToken; @property (copy, nonatomic) NSString *anonID; @property (copy, nonatomic) NSString *sessionID; -@property (copy, nonatomic) NSString *linkClickIdentifier; -@property (copy, nonatomic) NSString *spotlightIdentifier; -@property (copy, nonatomic) NSString *universalLinkUrl; @property (copy, nonatomic) NSString *initialReferrer; @property (copy, nonatomic) NSString *userUrl; @property (copy, nonatomic) NSString *localUrl; @@ -46,11 +42,9 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (assign, nonatomic) NSInteger retryCount; @property (assign, nonatomic) NSTimeInterval retryInterval; @property (assign, nonatomic) NSTimeInterval timeout; -@property (copy, nonatomic) NSString *externalIntentURI; @property (strong, nonatomic) NSMutableDictionary *savedAnalyticsData; @property (copy, nonatomic) NSString *lastSystemBuildVersion; @property (copy, nonatomic) NSString *browserUserAgentString; -@property (copy, nonatomic) NSString *referringURL; @property (assign, nonatomic) BOOL limitFacebookTracking; @property (strong, nonatomic) NSDate *previousAppBuildDate; @property (assign, nonatomic, readwrite) BOOL disableAdNetworkCallouts; @@ -58,7 +52,6 @@ NSURL* /* _Nonnull */ BNCURLForBranchDirectory(void); @property (nonatomic, copy, readwrite) NSString *patternListURL; @property (strong, nonatomic) NSArray *savedURLPatternList; @property (assign, nonatomic) NSInteger savedURLPatternListVersion; -@property (assign, nonatomic) BOOL dropURLOpen; @property (assign, nonatomic) BOOL trackingDisabled; From 31e584adb69d0ee9a56d709ee67168c019de58c1 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:25:11 -0800 Subject: [PATCH 03/10] Fixed syntax error. --- 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 21baf2fcc..7dae36ad7 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -2093,7 +2093,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } req.callback = initSessionCallback; req.urlString = urlString; - req.linkParams = params + req.linkParams = params; [self.requestQueue insert:req at:0]; From 18f3c96eaaac63a7ae8c3a068d165dde4736acad Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:31:59 -0800 Subject: [PATCH 04/10] Removed externalIntentURI and universalLinkUrl fields. They are same as referringURL. --- Sources/BranchSDK/BNCRequestFactory.m | 3 --- Sources/BranchSDK/Branch.m | 10 ++-------- Sources/BranchSDK/Private/BranchOpenRequest.h | 2 -- 3 files changed, 2 insertions(+), 13 deletions(-) diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 26c5a824e..0cfe91224 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -312,9 +312,6 @@ - (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromRequestObject:( [self safeSetValue:openRequest.linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json]; [self safeSetValue:openRequest.linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json]; - - // This was only on opens before, cause it can't exist on install. - [self safeSetValue:openRequest.linkParams.externalIntentURI forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } - (void)addSystemObserverDataToJSON:(NSMutableDictionary *)json { diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 7dae36ad7..a40832062 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -687,7 +687,6 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options if ([options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { id branchUrlFromPush = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY]; if ([branchUrlFromPush isKindOfClass:[NSString class]]) { - params.universalLinkUrl = branchUrlFromPush; params.referringURL = branchUrlFromPush; pushURL = (NSString *)branchUrlFromPush; } @@ -748,7 +747,6 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier params.dropURLOpen = YES; NSString *urlString = [url absoluteString]; - params.externalIntentURI = urlString; params.referringURL = urlString; [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil urlParams:params reset:YES]; @@ -772,20 +770,17 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce NSString *urlScheme = [url scheme]; - // save the incoming url in the preferenceHelper in the externalIntentURI field if ([self.allowedSchemeList count]) { for (NSString *scheme in self.allowedSchemeList) { if (urlScheme && [scheme isEqualToString:urlScheme]) { - openRequestParams.externalIntentURI = [url absoluteString]; openRequestParams.referringURL = [url absoluteString]; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Allowed scheme list, set referringURL to %@", [url absoluteString]] error:nil]; break; } } } else { - openRequestParams.externalIntentURI = [url absoluteString]; openRequestParams.referringURL = [url absoluteString]; - [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set externalIntentURI and referringURL to %@", [url absoluteString]] error:nil]; + [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set referringURL to %@", [url absoluteString]] error:nil]; } NSString *query = [url fragment]; @@ -830,7 +825,6 @@ - (BOOL)handleUniversalDeepLink_private:(NSString*)urlString sceneIdentifier:(NS BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; if (urlString.length) { - params.universalLinkUrl = urlString; params.referringURL = urlString; [[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Set universalLinkUrl and referringURL to %@", urlString] error:nil]; } diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index cd348520b..e7fba3c17 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -12,9 +12,7 @@ @interface BranchOpenRequestLinkParams : NSObject @property (copy, nonatomic) NSString *linkClickIdentifier; @property (copy, nonatomic) NSString *spotlightIdentifier; -@property (copy, nonatomic) NSString *universalLinkUrl; @property (copy, nonatomic) NSString *referringURL; -@property (copy, nonatomic) NSString *externalIntentURI; @property (assign, nonatomic) BOOL dropURLOpen; @end From 2db6c7fde3d6ec3eee8f808ba1a6d6b2cd7da3cd Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 12:39:07 -0800 Subject: [PATCH 05/10] Fixed commented code. --- Sources/BranchSDK/BNCRequestFactory.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 0cfe91224..5267a13f2 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -107,15 +107,15 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - /* if (openRequest.) { - NSURL *url = [NSURL URLWithString:urlString]; + if (installRequest.urlString) { + NSURL *url = [NSURL URLWithString:installRequest.urlString]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { - [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; + [self safeSetValue:installRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; } else { - [self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; + [self safeSetValue:installRequest.urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } } - */ + [self addAppleAttributionTokenToJSON:json]; // Install Only From f99ce4227f8046d105de03c9ba545b672bd098b1 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:27:13 -0800 Subject: [PATCH 06/10] Replace parameter "urlString:" of function initUserSessionAndCallCallback with params.referringURL. They both are same. --- Sources/BranchSDK/BNCRequestFactory.m | 4 +-- Sources/BranchSDK/Branch.m | 43 ++++++++++++++------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 5267a13f2..9940afa3a 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -107,7 +107,7 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (installRequest.urlString) { + if (installRequest.urlString && !installRequest.linkParams.dropURLOpen) { NSURL *url = [NSURL URLWithString:installRequest.urlString]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { [self safeSetValue:installRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; @@ -163,7 +163,7 @@ - (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (openRequest.urlString) { + if (openRequest.urlString && !openRequest.linkParams.dropURLOpen) { NSURL *url = [NSURL URLWithString:openRequest.urlString]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { [self safeSetValue:openRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index a40832062..7e12500b0 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -533,7 +533,7 @@ + (void)setTrackingDisabled:(BOOL)disabled { // Set the flag: [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: - [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil urlParams:nil reset:NO]; + [Branch.getInstance initUserSessionAndCallCallback:NO sceneIdentifier:nil urlParams:nil reset:NO]; } } } @@ -582,7 +582,7 @@ - (void)setConsumerProtectionAttributionLevel:(BranchAttributionLevel)level { [BNCPreferenceHelper sharedInstance].trackingDisabled = NO; // Initialize a Branch session: - [[Branch getInstance] initUserSessionAndCallCallback:NO sceneIdentifier:nil urlString:nil urlParams:nil reset:true]; + [[Branch getInstance] initUserSessionAndCallCallback:NO sceneIdentifier:nil urlParams:nil reset:true]; } } @@ -694,7 +694,7 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options #endif if(pushURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) { - [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlString:pushURL urlParams:params reset:NO]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlParams:params reset:NO]; } } @@ -749,7 +749,7 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier NSString *urlString = [url absoluteString]; params.referringURL = urlString; - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:nil urlParams:params reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:params reset:YES]; return NO; } @@ -794,7 +794,7 @@ - (BOOL)handleSchemeDeepLink_private:(NSURL*)url sceneIdentifier:(NSString *)sce openRequestParams.linkClickIdentifier = params[@"link_click_id"]; } } - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:url.absoluteString urlParams:openRequestParams reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:openRequestParams reset:YES]; return handled; } @@ -829,7 +829,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 urlParams:params reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:params reset:YES]; return [Branch isBranchLink:urlString]; } @@ -870,7 +870,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS } #endif - [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlString:userActivity.webpageURL.absoluteString urlParams:params reset:YES]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:params reset:YES]; return spotlightIdentifier != nil; } @@ -1770,7 +1770,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 urlParams:nil reset:NO]; + [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlParams:nil reset:NO]; } }); } @@ -1997,25 +1997,28 @@ - (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 urlParams:nil reset:NO]; + [self initUserSessionAndCallCallback:NO sceneIdentifier:nil urlParams:nil reset:NO]; } } -- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString urlParams:(BranchOpenRequestLinkParams *)params reset:(BOOL)reset { +- (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlParams:(BranchOpenRequestLinkParams *)params reset:(BOOL)reset { @synchronized (self) { if (self.deferInitForPluginRuntime) { - if (urlString) { + if ( params.referringURL) { [[BranchLogger shared] logDebug:@"Branch init is deferred, caching link" error:nil]; - self.cachedURLString = urlString; + self.cachedURLString = params.referringURL; } else { [[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] error:nil]; + if (self.cachedURLString && !params.referringURL) { + if(!params){ + params = [[BranchOpenRequestLinkParams alloc] init]; + } + params.referringURL = self.cachedURLString; + [[BranchLogger shared] logDebug:[NSString stringWithFormat:@"Using cached link: %@", params.referringURL] error:nil]; } self.cachedURLString = nil; } @@ -2027,7 +2030,7 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr // If the session is not yet initialized OR // If the session is already initialized or is initializing but we need to reset it. if ( reset || self.initializationStatus == BNCInitStatusUninitialized) { - [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier urlString:urlString urlParams:params]; + [self initializeSessionAndCallCallback:callCallback sceneIdentifier:sceneIdentifier urlParams:params]; } // If the session was initialized, but callCallback was specified, do so. else if (callCallback && self.initializationStatus == BNCInitStatusInitialized) { @@ -2048,7 +2051,7 @@ - (void)initUserSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSStr } // only called from initUserSessionAndCallCallback! -- (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlString:(NSString *)urlString urlParams:(BranchOpenRequestLinkParams *)params { +- (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSString *)sceneIdentifier urlParams:(BranchOpenRequestLinkParams *)params { // BranchDelegate willStartSessionWithURL notification NSURL *URL = (params.referringURL.length) ? [NSURL URLWithString:params.referringURL] : nil; @@ -2086,7 +2089,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS req = [[BranchInstallRequest alloc] initWithCallback:initSessionCallback]; } req.callback = initSessionCallback; - req.urlString = urlString; + req.urlString = params.referringURL; req.linkParams = params; [self.requestQueue insert:req at:0]; @@ -2097,10 +2100,10 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS } else { // new link arrival but an install or open is already on queue? need a new open for link resolution. - if (urlString) { + if (params.referringURL) { req = [[BranchOpenRequest alloc] initWithCallback:initSessionCallback]; req.callback = initSessionCallback; - req.urlString = urlString; + req.urlString = params.referringURL; req.linkParams = params; // put it behind the one that's already on queue From f195d92630edb90df80d819330634e83d0aa4cfe Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:30:08 -0800 Subject: [PATCH 07/10] Added param referringURL to func saveAppClipData. --- Sources/BranchSDK/BranchOpenRequest.m | 2 +- Sources/BranchSDK/Private/BNCAppGroupsData.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index bf0c74b27..a1707b98d 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -166,7 +166,7 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { [BranchOpenRequest releaseOpenResponseLock]; if (self.isInstall) { - [[BNCAppGroupsData shared] saveAppClipData]; + [[BNCAppGroupsData shared] saveAppClipData: self.linkParams.referringURL]; } #if !TARGET_OS_TV diff --git a/Sources/BranchSDK/Private/BNCAppGroupsData.h b/Sources/BranchSDK/Private/BNCAppGroupsData.h index 7626a2d46..5fcbc43ac 100644 --- a/Sources/BranchSDK/Private/BNCAppGroupsData.h +++ b/Sources/BranchSDK/Private/BNCAppGroupsData.h @@ -25,7 +25,7 @@ NS_ASSUME_NONNULL_BEGIN + (instancetype)shared; // saves app clip data when appropriate -- (void)saveAppClipData; +- (void)saveAppClipData:(NSString *) referringURL ; // loads app clip data - (BOOL)loadAppClipData; From 943ab31246664189f03a34c95288a7388f073af8 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:07:03 -0800 Subject: [PATCH 08/10] Removed param urlString from BranchOpenRequest class urlString holds the same value as linkparams.referringURL. So removed urlString and adjusted other functions to use linkparams.referringURL instead. --- Sources/BranchSDK/BNCRequestFactory.m | 30 +++++++++---------- Sources/BranchSDK/Branch.m | 6 ++-- Sources/BranchSDK/BranchInstallRequest.m | 2 +- Sources/BranchSDK/BranchOpenRequest.m | 10 +++---- Sources/BranchSDK/Private/BNCRequestFactory.h | 4 +-- Sources/BranchSDK/Private/BranchOpenRequest.h | 5 ++-- 6 files changed, 27 insertions(+), 30 deletions(-) diff --git a/Sources/BranchSDK/BNCRequestFactory.m b/Sources/BranchSDK/BNCRequestFactory.m index 9940afa3a..7d62a4692 100644 --- a/Sources/BranchSDK/BNCRequestFactory.m +++ b/Sources/BranchSDK/BNCRequestFactory.m @@ -82,7 +82,7 @@ - (BOOL)isTrackingDisabled { return Branch.trackingDisabled; } -- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest { +- (NSDictionary *)dataForInstallWithLinkParams:(BranchOpenRequestLinkParams *) linkParams { NSMutableDictionary *json = [NSMutableDictionary new]; // All requests @@ -101,18 +101,18 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta // Install and Open [self addDeveloperUserIDToJSON:json]; [self addSystemObserverDataToJSON:json]; - [self addOpenRequestDataToJSON:json fromRequestObject:installRequest]; + [self addOpenRequestDataToJSON:json fromLinkParams:linkParams]; [self addPartnerParametersToJSON:json]; [self addAppleReceiptSourceToJSON:json]; [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (installRequest.urlString && !installRequest.linkParams.dropURLOpen) { - NSURL *url = [NSURL URLWithString:installRequest.urlString]; + if (linkParams.referringURL && !linkParams.dropURLOpen) { + NSURL *url = [NSURL URLWithString:linkParams.referringURL]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { - [self safeSetValue:installRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; + [self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; } else { - [self safeSetValue:installRequest.urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; + [self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } } @@ -134,7 +134,7 @@ - (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) insta return json; } -- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest { +- (NSDictionary *)dataForOpenWithLinkParams:(BranchOpenRequestLinkParams *) linkParams{ NSMutableDictionary *json = [NSMutableDictionary new]; // All requests @@ -156,19 +156,19 @@ - (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest // Install and Open [self addDeveloperUserIDToJSON:json]; [self addSystemObserverDataToJSON:json]; - [self addOpenRequestDataToJSON:json fromRequestObject:openRequest]; + [self addOpenRequestDataToJSON:json fromLinkParams:linkParams]; [self addPartnerParametersToJSON:json]; [self addAppleReceiptSourceToJSON:json]; [self addTimestampsToJSON:json]; // Check if the urlString is a valid URL to ensure it's a universal link, not the external intent uri - if (openRequest.urlString && !openRequest.linkParams.dropURLOpen) { - NSURL *url = [NSURL URLWithString:openRequest.urlString]; + if (linkParams.referringURL && !linkParams.dropURLOpen) { + NSURL *url = [NSURL URLWithString:linkParams.referringURL]; if (url && ([url.scheme isEqualToString:@"http"] || [url.scheme isEqualToString:@"https"])) { - [self safeSetValue:openRequest.urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; + [self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json]; } else { - [self safeSetValue:openRequest.urlString forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; + [self safeSetValue:linkParams.referringURL forKey:BRANCH_REQUEST_KEY_EXTERNAL_INTENT_URI onDict:json]; } } @@ -305,12 +305,12 @@ - (void)addShortURLTokensToJSON:(NSMutableDictionary *)json isSpotlightRequest:( json[BRANCH_REQUEST_KEY_SESSION_ID] = self.preferenceHelper.sessionID; } -- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromRequestObject:(BranchOpenRequest *) openRequest{ +- (void)addOpenRequestDataToJSON:(NSMutableDictionary *)json fromLinkParams:(BranchOpenRequestLinkParams *) linkParams{ json[BRANCH_REQUEST_KEY_DEBUG] = @(self.preferenceHelper.isDebug); [self safeSetValue:self.preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:json]; - [self safeSetValue:openRequest.linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json]; - [self safeSetValue:openRequest.linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json]; + [self safeSetValue:linkParams.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json]; + [self safeSetValue:linkParams.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json]; } diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 7e12500b0..236cde5d5 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -2089,12 +2089,11 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS req = [[BranchInstallRequest alloc] initWithCallback:initSessionCallback]; } req.callback = initSessionCallback; - req.urlString = params.referringURL; req.linkParams = params; [self.requestQueue insert:req at:0]; - NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString]; + NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link params %@", req, req.callback, req.linkParams]; [[BranchLogger shared] logDebug:message error:nil]; } else { @@ -2103,14 +2102,13 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS if (params.referringURL) { req = [[BranchOpenRequest alloc] initWithCallback:initSessionCallback]; req.callback = initSessionCallback; - req.urlString = params.referringURL; req.linkParams = params; // put it behind the one that's already on queue [self.requestQueue insert:req at:1]; [[BranchLogger shared] logDebug:@"Link resolution request" error:nil]; - NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString]; + NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link params%@", req, req.callback, req.linkParams]; [[BranchLogger shared] logDebug:message error:nil]; } } diff --git a/Sources/BranchSDK/BranchInstallRequest.m b/Sources/BranchSDK/BranchInstallRequest.m index b28c18b54..6f7ebabbe 100644 --- a/Sources/BranchSDK/BranchInstallRequest.m +++ b/Sources/BranchSDK/BranchInstallRequest.m @@ -20,7 +20,7 @@ - (id)initWithCallback:(callbackWithStatus)callback { - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *params = [factory dataForInstallWithRequestObject:self]; + NSDictionary *params = [factory dataForInstallWithLinkParams:self.linkParams]; [serverInterface postRequest:params url:[[BNCServerAPI sharedInstance] installServiceURL] key:key callback:callback]; } diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index a1707b98d..9d68810bd 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -47,7 +47,7 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall { - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key callback:(BNCServerCallback)callback { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:key UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *params = [factory dataForOpenWithRequestObject:self]; + NSDictionary *params = [factory dataForOpenWithLinkParams:self.linkParams]; [serverInterface postRequest:params url:[[BNCServerAPI sharedInstance] openServiceURL] @@ -140,8 +140,8 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { } NSString *referringURL = nil; - if (self.urlString.length > 0) { - referringURL = self.urlString; + if (self.linkParams.referringURL.length > 0) { + referringURL = self.linkParams.referringURL; } else { NSDictionary *sessionDataDict = [BNCEncodingUtils decodeJsonStringToDictionary:sessionData]; NSString *link = sessionDataDict[BRANCH_RESPONSE_KEY_BRANCH_REFERRING_LINK]; @@ -249,13 +249,13 @@ - (NSString *)getActionName { - (instancetype)initWithCoder:(NSCoder *)decoder { self = [super initWithCoder:decoder]; if (!self) return self; - self.urlString = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"]; + self.linkParams.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"]; return self; } - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; - [coder encodeObject:self.urlString forKey:@"urlString"]; + [coder encodeObject:self.linkParams.referringURL forKey:@"urlString"]; } + (BOOL)supportsSecureCoding { diff --git a/Sources/BranchSDK/Private/BNCRequestFactory.h b/Sources/BranchSDK/Private/BNCRequestFactory.h index 1d89527a4..403f831bd 100644 --- a/Sources/BranchSDK/Private/BNCRequestFactory.h +++ b/Sources/BranchSDK/Private/BNCRequestFactory.h @@ -25,8 +25,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithBranchKey:(NSString *)key UUID:(NSString *)requestUUID TimeStamp:(NSNumber *)requestTimeStamp NS_DESIGNATED_INITIALIZER; - (instancetype)init NS_UNAVAILABLE; -- (NSDictionary *)dataForInstallWithRequestObject:(BranchInstallRequest *) installRequest; -- (NSDictionary *)dataForOpenWithRequestObject:(BranchOpenRequest *) openRequest; +- (NSDictionary *)dataForInstallWithLinkParams:(BranchOpenRequestLinkParams *) linkParams; +- (NSDictionary *)dataForOpenWithLinkParams:(BranchOpenRequestLinkParams *) linkParams; // Event data is passed in - (NSDictionary *)dataForEventWithEventDictionary:(NSMutableDictionary *)dictionary; diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index e7fba3c17..a5e414afb 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -12,14 +12,13 @@ @interface BranchOpenRequestLinkParams : NSObject @property (copy, nonatomic) NSString *linkClickIdentifier; @property (copy, nonatomic) NSString *spotlightIdentifier; -@property (copy, nonatomic) NSString *referringURL; +@property (copy, nonatomic) NSString *referringURL; // URL that triggered this install or open event @property (assign, nonatomic) BOOL dropURLOpen; @end @interface BranchOpenRequest : BNCServerRequest -// URL that triggered this install or open event -@property (nonatomic, copy, readwrite) NSString *urlString; + @property (nonatomic, copy) callbackWithStatus callback; @property (nonatomic, copy, readwrite) BranchOpenRequestLinkParams *linkParams; From 2d63de1194c247e06c1b7387c21f2987a220e357 Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Wed, 4 Dec 2024 09:24:04 -0800 Subject: [PATCH 09/10] Fixed Unit tests and added encoding functions * Fixed property type of linkParams (strong) and added code to initialize it. * Added encoding functions for class BranchOpenRequestLinkParams. * Fixed value passed to saveAppClipData. It should be local variable referringURL. --- .../BNCClassSerializationTests.m | 10 ++++--- .../BNCPreferenceHelperTests.m | 7 ----- .../Branch-SDK-Tests/BNCRequestFactoryTests.m | 10 +++---- Sources/BranchSDK/BranchOpenRequest.m | 26 ++++++++++++++++--- Sources/BranchSDK/Private/BNCRequestFactory.h | 1 - Sources/BranchSDK/Private/BranchOpenRequest.h | 4 +-- 6 files changed, 35 insertions(+), 23 deletions(-) diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m index f1af287d9..d6293a4b3 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCClassSerializationTests.m @@ -71,7 +71,8 @@ - (void)testBranchEventRequestArchive { - (void)testBranchOpenRequestArchive { BranchOpenRequest *request = [[BranchOpenRequest alloc] initWithCallback:nil]; - request.urlString = @"https://branch.io"; + request.linkParams = [[BranchOpenRequestLinkParams alloc] init]; + request.linkParams.referringURL = @"https://branch.io"; // archive the event NSError *error = nil; @@ -88,14 +89,15 @@ - (void)testBranchOpenRequestArchive { XCTAssertTrue([object isKindOfClass:BranchOpenRequest.class]); BranchOpenRequest *unarchivedRequest = (BranchOpenRequest *)object; - XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]); + XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]); XCTAssertNil(unarchivedRequest.callback); XCTAssertTrue([@"open" isEqualToString:[unarchivedRequest getActionName]]); } - (void)testBranchInstallRequestArchive { BranchInstallRequest *request = [[BranchInstallRequest alloc] initWithCallback:nil]; - request.urlString = @"https://branch.io"; + request.linkParams = [[BranchOpenRequestLinkParams alloc] init]; + request.linkParams.referringURL = @"https://branch.io"; // archive the event NSError *error = nil; @@ -112,7 +114,7 @@ - (void)testBranchInstallRequestArchive { XCTAssertTrue([object isKindOfClass:BranchInstallRequest.class]); BranchInstallRequest *unarchivedRequest = (BranchInstallRequest *)object; - XCTAssertTrue([request.urlString isEqualToString:unarchivedRequest.urlString]); + XCTAssertTrue([request.linkParams.referringURL isEqualToString:unarchivedRequest.linkParams.referringURL]); XCTAssertNil(unarchivedRequest.callback); XCTAssertTrue([@"install" isEqualToString:[unarchivedRequest getActionName]]); } diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m index be4b97294..bf76adc51 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCPreferenceHelperTests.m @@ -243,13 +243,6 @@ - (void)testSetLastStrongMatchDate { XCTAssertEqualObjects(expectedDate, actualDate); } -- (void)testSetAppVersion { - NSString *expectedVersion = @"1.0.0"; - [self.prefHelper setAppVersion: expectedVersion]; - - NSString *actualVersion = [self.prefHelper appVersion]; - XCTAssertEqualObjects(expectedVersion, actualVersion); -} - (void)testSetLocalUrl { NSString *expectedLocalURL = @"https://local.example.com"; diff --git a/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m b/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m index c28d3b6e0..f9796c165 100644 --- a/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m +++ b/Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m @@ -29,7 +29,7 @@ - (void)tearDown { - (void)testInitWithBranchKeyNil { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil UUID:_requestUUID TimeStamp:_requestCreationTimeStamp]; - NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; + NSDictionary *json = [factory dataForInstallWithLinkParams:nil]; XCTAssertNotNil(json); // key is omitted when nil @@ -40,7 +40,7 @@ - (void)testInitWithBranchKeyNil { - (void)testInitWithBranchKeyEmpty { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; + NSDictionary *json = [factory dataForInstallWithLinkParams:nil]; XCTAssertNotNil(json); // empty string is allowed @@ -52,7 +52,7 @@ - (void)testInitWithBranchKeyEmpty { - (void)testInitWithBranchKey { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; + NSDictionary *json = [factory dataForInstallWithLinkParams:nil]; XCTAssertNotNil(json); XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]); @@ -62,7 +62,7 @@ - (void)testInitWithBranchKey { - (void)testDataForInstall { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"]; + NSDictionary *json = [factory dataForInstallWithLinkParams:nil]; XCTAssertNotNil(json); XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]); @@ -79,7 +79,7 @@ - (void)testDataForInstall { - (void)testDataForOpen { BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd" UUID:self.requestUUID TimeStamp:self.requestCreationTimeStamp]; - NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"]; + NSDictionary *json = [factory dataForInstallWithLinkParams:nil]; XCTAssertNotNil(json); XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]); diff --git a/Sources/BranchSDK/BranchOpenRequest.m b/Sources/BranchSDK/BranchOpenRequest.m index 9d68810bd..2fa8b2b67 100644 --- a/Sources/BranchSDK/BranchOpenRequest.m +++ b/Sources/BranchSDK/BranchOpenRequest.m @@ -40,6 +40,7 @@ - (id)initWithCallback:(callbackWithStatus)callback isInstall:(BOOL)isInstall { if ((self = [super init])) { _callback = callback; _isInstall = isInstall; + _linkParams = [[BranchOpenRequestLinkParams alloc] init]; } return self; @@ -166,7 +167,7 @@ - (void)processResponse:(BNCServerResponse *)response error:(NSError *)error { [BranchOpenRequest releaseOpenResponseLock]; if (self.isInstall) { - [[BNCAppGroupsData shared] saveAppClipData: self.linkParams.referringURL]; + [[BNCAppGroupsData shared] saveAppClipData: referringURL]; } #if !TARGET_OS_TV @@ -248,14 +249,15 @@ - (NSString *)getActionName { - (instancetype)initWithCoder:(NSCoder *)decoder { self = [super initWithCoder:decoder]; - if (!self) return self; - self.linkParams.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"urlString"]; + if (self) { + self.linkParams = [decoder decodeObjectOfClass:BranchOpenRequestLinkParams.class forKey:@"urlString"]; + } return self; } - (void)encodeWithCoder:(NSCoder *)coder { [super encodeWithCoder:coder]; - [coder encodeObject:self.linkParams.referringURL forKey:@"urlString"]; + [coder encodeObject:self.linkParams forKey:@"urlString"]; } + (BOOL)supportsSecureCoding { @@ -322,4 +324,20 @@ - (instancetype)init return self; } +- (instancetype)initWithCoder:(NSCoder *)decoder { + self = [super init]; + if (self) { + self.referringURL = [decoder decodeObjectOfClass:NSString.class forKey:@"referringURL"]; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeObject:self.referringURL forKey:@"referringURL"]; +} + ++ (BOOL)supportsSecureCoding { + return YES; +} + @end diff --git a/Sources/BranchSDK/Private/BNCRequestFactory.h b/Sources/BranchSDK/Private/BNCRequestFactory.h index 403f831bd..187dcc818 100644 --- a/Sources/BranchSDK/Private/BNCRequestFactory.h +++ b/Sources/BranchSDK/Private/BNCRequestFactory.h @@ -8,7 +8,6 @@ #import #import "BranchOpenRequest.h" -#import "BranchInstallRequest.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/BranchSDK/Private/BranchOpenRequest.h b/Sources/BranchSDK/Private/BranchOpenRequest.h index a5e414afb..95022cb1c 100644 --- a/Sources/BranchSDK/Private/BranchOpenRequest.h +++ b/Sources/BranchSDK/Private/BranchOpenRequest.h @@ -9,7 +9,7 @@ #import "BNCServerRequest.h" #import "BNCCallbacks.h" -@interface BranchOpenRequestLinkParams : NSObject +@interface BranchOpenRequestLinkParams : NSObject @property (copy, nonatomic) NSString *linkClickIdentifier; @property (copy, nonatomic) NSString *spotlightIdentifier; @property (copy, nonatomic) NSString *referringURL; // URL that triggered this install or open event @@ -20,7 +20,7 @@ @property (nonatomic, copy) callbackWithStatus callback; -@property (nonatomic, copy, readwrite) BranchOpenRequestLinkParams *linkParams; +@property (nonatomic, strong, readwrite) BranchOpenRequestLinkParams *linkParams; + (void) waitForOpenResponseLock; + (void) releaseOpenResponseLock; From 440bb30a649dba4176cefbd65cb63e9088d7b2cc Mon Sep 17 00:00:00 2001 From: NidhiDixit09 <93544270+NidhiDixit09@users.noreply.github.com> Date: Wed, 4 Dec 2024 15:54:10 -0800 Subject: [PATCH 10/10] Removed extra variables and initialized missing params.referringURL --- Sources/BranchSDK/Branch.m | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Sources/BranchSDK/Branch.m b/Sources/BranchSDK/Branch.m index 236cde5d5..aa83e3928 100644 --- a/Sources/BranchSDK/Branch.m +++ b/Sources/BranchSDK/Branch.m @@ -681,19 +681,17 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options self.shouldAutomaticallyDeepLink = automaticallyDisplayController; // Check for Branch link in a push payload - NSString *pushURL = nil; BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; #if !TARGET_OS_TV if ([options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { id branchUrlFromPush = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY]; if ([branchUrlFromPush isKindOfClass:[NSString class]]) { - params.referringURL = branchUrlFromPush; - pushURL = (NSString *)branchUrlFromPush; + params.referringURL = (NSString *)branchUrlFromPush; } } #endif - if(pushURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) { + if(params.referringURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) { [self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlParams:params reset:NO]; } } @@ -742,15 +740,11 @@ - (BOOL)handleDeepLink:(NSURL *)url sceneIdentifier:(NSString *)sceneIdentifier pattern = [self.userURLFilter patternMatchingURL:url]; } - BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; if (pattern) { + BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init]; params.dropURLOpen = YES; - - NSString *urlString = [url absoluteString]; - params.referringURL = urlString; - + params.referringURL = [url absoluteString];; [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:params reset:YES]; - return NO; } @@ -869,7 +863,7 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity sceneIdentifier:(NSS } } #endif - + params.referringURL = userActivity.webpageURL.absoluteString; [self initUserSessionAndCallCallback:YES sceneIdentifier:sceneIdentifier urlParams:params reset:YES]; return spotlightIdentifier != nil;