Skip to content

Commit a2e03af

Browse files
aaustinE-B-Smith
authored andcommitted
INTENG-3137 Handle duplicate local attribution calls (#558)
* Handle duplicate local attribution calls * Match getter setter to variable * Better boolean logic
1 parent 51acc04 commit a2e03af

File tree

7 files changed

+42
-3
lines changed

7 files changed

+42
-3
lines changed

Branch-SDK/Branch-SDK/BNCPreferenceHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
@property (assign, nonatomic) BOOL shouldWaitForInit;
3232
@property (assign, nonatomic) BOOL suppressWarningLogs;
3333
@property (assign, nonatomic) BOOL checkedFacebookAppLinks;
34+
@property (assign, nonatomic) BOOL checkedAppleSearchAdAttribution;
3435
@property (assign, nonatomic) NSInteger retryCount;
3536
@property (assign, nonatomic) NSTimeInterval retryInterval;
3637
@property (assign, nonatomic) NSTimeInterval timeout;

Branch-SDK/Branch-SDK/BNCPreferenceHelper.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
NSString * const BRANCH_PREFS_KEY_IDENTITY_ID = @"bnc_identity_id";
2727
NSString * const BRANCH_PREFS_KEY_IDENTITY = @"bnc_identity";
2828
NSString * const BRANCH_PREFS_KEY_CHECKED_FACEBOOK_APP_LINKS = @"bnc_checked_fb_app_links";
29+
NSString * const BRANCH_PREFS_KEY_CHECKED_APPLE_SEARCH_ADS = @"bnc_checked_apple_search_ads";
2930
NSString * const BRANCH_PREFS_KEY_APPLE_SEARCH_ADS_INFO = @"bnc_apple_search_ads_info";
3031
NSString * const BRANCH_PREFS_KEY_LINK_CLICK_IDENTIFIER = @"bnc_link_click_identifier";
3132
NSString * const BRANCH_PREFS_KEY_SPOTLIGHT_IDENTIFIER = @"bnc_spotlight_identifier";
@@ -80,6 +81,7 @@ @implementation BNCPreferenceHelper
8081
timeout = _timeout,
8182
lastStrongMatchDate = _lastStrongMatchDate,
8283
checkedFacebookAppLinks = _checkedFacebookAppLinks,
84+
checkedAppleSearchAdAttribution = _checkedAppleSearchAdAttribution,
8385
appleSearchAdDetails = _appleSearchAdDetails,
8486
requestMetadataDictionary = _requestMetadataDictionary,
8587
instrumentationDictionary = _instrumentationDictionary;
@@ -444,6 +446,17 @@ - (void)setUserUrl:(NSString *)userUrl {
444446
}
445447
}
446448

449+
- (BOOL)checkedAppleSearchAdAttribution {
450+
_checkedAppleSearchAdAttribution = [self readBoolFromDefaults:BRANCH_PREFS_KEY_CHECKED_APPLE_SEARCH_ADS];
451+
return _checkedAppleSearchAdAttribution;
452+
}
453+
454+
- (void)setCheckedAppleSearchAdAttribution:(BOOL)checked {
455+
_checkedAppleSearchAdAttribution = checked;
456+
[self writeBoolToDefaults:BRANCH_PREFS_KEY_CHECKED_APPLE_SEARCH_ADS value:checked];
457+
}
458+
459+
447460
- (BOOL)checkedFacebookAppLinks {
448461
_checkedFacebookAppLinks = [self readBoolFromDefaults:BRANCH_PREFS_KEY_CHECKED_FACEBOOK_APP_LINKS];
449462
return _checkedFacebookAppLinks;

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
9191
@property (copy, nonatomic) callbackWithParams sessionInitWithParamsCallback;
9292
@property (copy, nonatomic) callbackWithBranchUniversalObject sessionInitWithBranchUniversalObjectCallback;
9393
@property (assign, nonatomic) NSInteger networkCount;
94+
@property (assign, nonatomic) NSInteger asyncRequestCount;
9495
@property (assign, nonatomic) BOOL isInitialized;
9596
@property (assign, nonatomic) BOOL shouldCallSessionInitCallback;
9697
@property (assign, nonatomic) BOOL shouldAutomaticallyDeepLink;
@@ -175,6 +176,7 @@ - (id)initWithInterface:(BNCServerInterface *)interface queue:(BNCServerRequestQ
175176
_shouldCallSessionInitCallback = YES;
176177
_processing_sema = dispatch_semaphore_create(1);
177178
_networkCount = 0;
179+
_asyncRequestCount = 0;
178180
_deepLinkControllers = [[NSMutableDictionary alloc] init];
179181
_whiteListedSchemeList = [[NSMutableArray alloc] init];
180182
_useCookieBasedMatching = YES;
@@ -370,9 +372,14 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options isReferrable:(BOOL)
370372
if (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] &&
371373
![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) {
372374

375+
self.asyncRequestCount = 0;
376+
373377
// If Facebook SDK is present, call deferred app link check here which will later on call initUserSession
374-
if (![self checkFacebookAppLinks] && ![self checkAppleSearchAdsAttribution]) {
375-
378+
[self checkFacebookAppLinks];
379+
// If developer opted in, call deferred apple search attribution API here which will later on call initUserSession
380+
[self checkAppleSearchAdsAttribution];
381+
382+
if (self.asyncRequestCount == 0) {
376383
// If we're not looking for App Links or Apple Search Ads, initialize
377384
[self initUserSessionAndCallCallback:YES];
378385
}
@@ -540,9 +547,11 @@ - (BOOL)checkAppleSearchAdsAttribution {
540547
id sharedClientInstance = ((id (*)(id, SEL))[ADClientClass methodForSelector:sharedClient])(ADClientClass, sharedClient);
541548

542549
self.preferenceHelper.shouldWaitForInit = YES;
550+
self.preferenceHelper.checkedAppleSearchAdAttribution = YES;
551+
self.asyncRequestCount++;
543552

544553
void (^__nullable completionBlock)(NSDictionary *attrDetails, NSError *error) = ^void(NSDictionary *__nullable attrDetails, NSError *__nullable error) {
545-
self.preferenceHelper.shouldWaitForInit = NO;
554+
self.asyncRequestCount--;
546555

547556
if (attrDetails && [attrDetails count]) {
548557
self.preferenceHelper.appleSearchAdDetails = attrDetails;
@@ -567,6 +576,11 @@ - (BOOL)checkAppleSearchAdsAttribution {
567576
self.preferenceHelper.appleSearchAdDetails = testInfo;
568577
}
569578

579+
// if there's another async attribution check in flight, don't continue with init
580+
if (self.asyncRequestCount > 0) { return; }
581+
582+
self.preferenceHelper.shouldWaitForInit = NO;
583+
570584
dispatch_async(dispatch_get_main_queue(), ^{
571585
[self initUserSessionAndCallCallback:!self.isInitialized];
572586
});
@@ -594,10 +608,17 @@ - (BOOL)checkFacebookAppLinks {
594608

595609
if ([self.FBSDKAppLinkUtility methodForSelector:fetchDeferredAppLink]) {
596610
void (^__nullable completionBlock)(NSURL *appLink, NSError *error) = ^void(NSURL *__nullable appLink, NSError *__nullable error) {
611+
self.asyncRequestCount--;
612+
613+
// if there's another async attribution check in flight, don't continue with init
614+
if (self.asyncRequestCount > 0) { return; }
615+
597616
self.preferenceHelper.shouldWaitForInit = NO;
617+
598618
[self handleDeepLink:appLink];
599619
};
600620

621+
self.asyncRequestCount++;
601622
self.preferenceHelper.checkedFacebookAppLinks = YES;
602623
self.preferenceHelper.shouldWaitForInit = YES;
603624

Branch-SDK/Branch-SDK/BranchConstants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ extern NSString * const BRANCH_REQUEST_KEY_OS_VERSION;
5050
extern NSString * const BRANCH_REQUEST_KEY_URI_SCHEME;
5151
extern NSString * const BRANCH_REQUEST_KEY_UPDATE;
5252
extern NSString * const BRANCH_REQUEST_KEY_CHECKED_FACEBOOK_APPLINKS;
53+
extern NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION;
5354
extern NSString * const BRANCH_REQUEST_KEY_LINK_IDENTIFIER;
5455
extern NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER;
5556
extern NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL;

Branch-SDK/Branch-SDK/BranchConstants.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
NSString * const BRANCH_REQUEST_KEY_UPDATE = @"update";
5252
NSString * const BRANCH_REQUEST_KEY_LINK_IDENTIFIER = @"link_identifier";
5353
NSString * const BRANCH_REQUEST_KEY_CHECKED_FACEBOOK_APPLINKS = @"facebook_app_link_checked";
54+
NSString * const BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION = @"apple_ad_attribution_checked";
5455
NSString * const BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER = @"spotlight_identifier";
5556
NSString * const BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL = @"universal_link_url";
5657
NSString * const BRANCH_REQUEST_KEY_BRAND = @"brand";

Branch-SDK/Branch-SDK/Requests/BranchInstallRequest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
3131
[self safeSetValue:[BNCSystemObserver getDefaultUriScheme] forKey:BRANCH_REQUEST_KEY_URI_SCHEME onDict:params];
3232
[self safeSetValue:[BNCSystemObserver getUpdateState] forKey:BRANCH_REQUEST_KEY_UPDATE onDict:params];
3333
[self safeSetValue:[NSNumber numberWithBool:preferenceHelper.checkedFacebookAppLinks] forKey:BRANCH_REQUEST_KEY_CHECKED_FACEBOOK_APPLINKS onDict:params];
34+
[self safeSetValue:[NSNumber numberWithBool:preferenceHelper.checkedAppleSearchAdAttribution] forKey:BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION onDict:params];
3435
[self safeSetValue:preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:params];
3536
[self safeSetValue:preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:params];
3637
[self safeSetValue:preferenceHelper.universalLinkUrl forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:params];

Branch-SDK/Branch-SDK/Requests/BranchOpenRequest.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ - (void)makeRequest:(BNCServerInterface *)serverInterface key:(NSString *)key ca
5454
[self safeSetValue:[BNCSystemObserver getDefaultUriScheme] forKey:BRANCH_REQUEST_KEY_URI_SCHEME onDict:params];
5555
[self safeSetValue:[BNCSystemObserver getUpdateState] forKey:BRANCH_REQUEST_KEY_UPDATE onDict:params];
5656
[self safeSetValue:[NSNumber numberWithBool:preferenceHelper.checkedFacebookAppLinks] forKey:BRANCH_REQUEST_KEY_CHECKED_FACEBOOK_APPLINKS onDict:params];
57+
[self safeSetValue:[NSNumber numberWithBool:preferenceHelper.checkedAppleSearchAdAttribution] forKey:BRANCH_REQUEST_KEY_CHECKED_APPLE_AD_ATTRIBUTION onDict:params];
5758
[self safeSetValue:preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:params];
5859
[self safeSetValue:preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:params];
5960
[self safeSetValue:preferenceHelper.universalLinkUrl forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:params];

0 commit comments

Comments
 (0)