Skip to content

Commit f632f4a

Browse files
authored
Merge pull request #913 from BranchMetrics/SDK-270-allow-shortlink-creation-when-tracking-is-disabled
Sdk 270 allow shortlink creation when tracking is disabled
2 parents e87fa54 + 3ca5093 commit f632f4a

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,7 @@ - (NSString *)generateShortUrl:(NSArray *)tags
18021802
linkData:linkData
18031803
linkCache:self.linkCache];
18041804

1805-
if ((self.initializationStatus == BNCInitStatusInitialized) && !self.preferenceHelper.trackingDisabled) {
1805+
if (self.initializationStatus == BNCInitStatusInitialized) {
18061806
BNCLogDebug(@"Creating a custom URL synchronously.");
18071807
BNCServerResponse *serverResponse = [req makeRequest:self.serverInterface key:self.class.branchKey];
18081808
shortURL = [req processResponse:serverResponse];
@@ -2064,23 +2064,21 @@ - (void)processNextQueueItem {
20642064

20652065
if (req) {
20662066

2067-
if (Branch.trackingDisabled) {
2068-
// If tracking is disabled keep failing everything in the queue.
2069-
}
2070-
else if (![req isKindOfClass:[BranchInstallRequest class]] && !self.preferenceHelper.identityID) {
2067+
if (![req isKindOfClass:[BranchInstallRequest class]] && !self.preferenceHelper.identityID) {
20712068
BNCLogError(@"User session has not been initialized!");
20722069
BNCPerformBlockOnMainThreadSync(^{
20732070
[req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]];
20742071
});
20752072
return;
2076-
}
2077-
else if (![req isKindOfClass:[BranchOpenRequest class]] &&
2073+
2074+
} else if (![req isKindOfClass:[BranchOpenRequest class]] &&
20782075
(!self.preferenceHelper.deviceFingerprintID || !self.preferenceHelper.sessionID)) {
20792076
BNCLogError(@"Missing session items!");
20802077
BNCPerformBlockOnMainThreadSync(^{
20812078
[req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]];
20822079
});
20832080
return;
2081+
20842082
}
20852083

20862084
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);

Branch-SDK/Branch-SDK/Networking/BNCServerInterface.m

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,9 @@ - (void)genericHTTPRequest:(NSURLRequest *)request
609609

610610
if (Branch.trackingDisabled) {
611611
NSString *endpoint = request.URL.absoluteString;
612-
BNCPreferenceHelper *prefs = [BNCPreferenceHelper preferenceHelper];
613-
if (([endpoint bnc_containsString:@"/v1/install"] ||
614-
[endpoint bnc_containsString:@"/v1/open"]) &&
615-
((prefs.linkClickIdentifier.length > 0 ) ||
616-
(prefs.spotlightIdentifier.length > 0 ) ||
617-
(prefs.universalLinkUrl.length > 0))) {
618-
// Allow this network operation since it's an open/install to resolve a link.
619-
} else {
612+
613+
// if endpoint is not on the whitelist, fail it.
614+
if (![self whiteListContainsEndpoint:endpoint]) {
620615
[[BNCPreferenceHelper preferenceHelper] clearTrackingInformation];
621616
NSError *error = [NSError branchErrorWithCode:BNCTrackingDisabledError];
622617
BNCLogError(@"Network service error: %@.", error);
@@ -626,6 +621,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request
626621
return;
627622
}
628623
}
624+
629625
id<BNCNetworkOperationProtocol> operation =
630626
[self.networkService networkOperationWithURLRequest:request.copy completion:completionHandler];
631627
[operation start];
@@ -639,6 +635,28 @@ - (void)genericHTTPRequest:(NSURLRequest *)request
639635
}
640636
}
641637

638+
- (BOOL)whiteListContainsEndpoint:(NSString *)endpoint {
639+
BNCPreferenceHelper *prefs = [BNCPreferenceHelper preferenceHelper];
640+
BOOL hasIdentifier = (prefs.linkClickIdentifier.length > 0 ) || (prefs.spotlightIdentifier.length > 0 ) || (prefs.universalLinkUrl.length > 0);
641+
642+
// Allow install to resolve a link.
643+
if ([endpoint bnc_containsString:@"/v1/install"] && hasIdentifier) {
644+
return YES;
645+
}
646+
647+
// Allow open to resolve a link.
648+
if ([endpoint bnc_containsString:@"/v1/open"] && hasIdentifier) {
649+
return YES;
650+
}
651+
652+
// Allow short url creation requests
653+
if ([endpoint bnc_containsString:@"/v1/url"]) {
654+
return YES;
655+
}
656+
657+
return NO;
658+
}
659+
642660
- (NSError*) verifyNetworkOperation:(id<BNCNetworkOperationProtocol>)operation {
643661

644662
if (!operation) {

0 commit comments

Comments
 (0)