Skip to content

Commit 29294e2

Browse files
authored
Misc Bug Fixes : SDK-2530, SDK-2532 (#1465)
* Bug Fixes : SDK-2530 & SDK SDK-2532 - Fixed isLinkingRelatedRequest function to allow opens if tracking is disabled and spotlight identifier is present. - Fixed race condition for push notification on cold launch. * Removed extra comment. * Added unit test for isLinkingRelatedRequest function
1 parent 5fa7de2 commit 29294e2

File tree

4 files changed

+52
-5
lines changed

4 files changed

+52
-5
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// BNCServerInterfaceTests.m
3+
// Branch-SDK-Tests
4+
//
5+
// Created by Nidhi Dixit on 1/7/25.
6+
// Copyright © 2025 Branch, Inc. All rights reserved.
7+
//
8+
9+
#import <XCTest/XCTest.h>
10+
#import "Branch/BNCServerInterface.h"
11+
12+
@interface BNCServerInterface()
13+
- (BOOL)isLinkingRelatedRequest:(NSString *)endpoint postParams:(NSDictionary *)post;
14+
@end
15+
16+
@interface BNCServerInterfaceTests : XCTestCase
17+
@end
18+
19+
@implementation BNCServerInterfaceTests
20+
21+
- (void)testIsLinkingRelatedRequest {
22+
23+
BNCServerInterface *serverInterface = [[BNCServerInterface alloc] init];
24+
25+
// install
26+
XCTAssertTrue([serverInterface isLinkingRelatedRequest:@"/v1/install" postParams:nil]);
27+
28+
// open
29+
XCTAssertFalse([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:nil]);
30+
XCTAssertFalse([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:@{}]);
31+
XCTAssertTrue([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:@{@"spotlight_identifier":@"io.branch.link.v1.url.testbed.app.link/1234"}]);
32+
XCTAssertTrue([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:@{@"link_identifier": @"1305991233204308323"}]);
33+
XCTAssertTrue([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:@{@"universal_link_url":@"branchtest://open?_branch_referrer=H4sIAAAAAAAAA8soKSkottLXT8pLLkktLklKTd"}]);
34+
XCTAssertFalse([serverInterface isLinkingRelatedRequest:@"/v1/open" postParams:@{@"uri_scheme" : @"branchtest"}]);
35+
36+
// v2/event
37+
XCTAssertFalse([serverInterface isLinkingRelatedRequest:@"/v2/event" postParams:@{@"spotlight_identifier":@"io.branch.link.v1.url.testbed.app.link/1234"}]);
38+
39+
// v1/url
40+
XCTAssertTrue([serverInterface isLinkingRelatedRequest:@"/v1/url" postParams:nil]);
41+
42+
}
43+
@end

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
C17DAF7B2AC20C2000B16B1A /* BranchClassTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C17DAF7A2AC20C2000B16B1A /* BranchClassTests.m */; };
235235
C1CC888229BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */; };
236236
E72489D228E40D0200DCD8FD /* PasteControlViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E72489D128E40D0200DCD8FD /* PasteControlViewController.m */; };
237+
E74B54402D2DB0660049A89D /* BNCServerInterfaceTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E74B543F2D2DB0660049A89D /* BNCServerInterfaceTests.m */; };
237238
E7A728BD2AA9A112009343B7 /* BNCAPIServerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E7A728BC2AA9A112009343B7 /* BNCAPIServerTest.m */; };
238239
F1CF14111F4CC79F00BB2694 /* CoreSpotlight.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 67F270881BA9FCFF002546A7 /* CoreSpotlight.framework */; settings = {ATTRIBUTES = (Required, ); }; };
239240
/* End PBXBuildFile section */
@@ -538,6 +539,7 @@
538539
C1CC888129BAAFC000BDD2B5 /* BNCReferringURLUtilityTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCReferringURLUtilityTests.m; sourceTree = "<group>"; };
539540
E72489D028E40D0200DCD8FD /* PasteControlViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PasteControlViewController.h; sourceTree = "<group>"; };
540541
E72489D128E40D0200DCD8FD /* PasteControlViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PasteControlViewController.m; sourceTree = "<group>"; };
542+
E74B543F2D2DB0660049A89D /* BNCServerInterfaceTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCServerInterfaceTests.m; sourceTree = "<group>"; };
541543
E7A728BC2AA9A112009343B7 /* BNCAPIServerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BNCAPIServerTest.m; sourceTree = "<group>"; };
542544
F1D4F9AC1F323F01002D13FF /* Branch-TestBed-UITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Branch-TestBed-UITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
543545
/* End PBXFileReference section */
@@ -648,6 +650,7 @@
648650
5F8650192B76DA3200364BDE /* NSMutableDictionaryBranchTests.m */,
649651
4D16839E2098C901008819E3 /* NSStringBranchTests.m */,
650652
5F6D86D82BB5E9650068B536 /* BNCClassSerializationTests.m */,
653+
E74B543F2D2DB0660049A89D /* BNCServerInterfaceTests.m */,
651654
);
652655
path = "Branch-SDK-Tests";
653656
sourceTree = "<group>";
@@ -1360,6 +1363,7 @@
13601363
files = (
13611364
4D1683B82098C902008819E3 /* BNCEncodingUtilsTests.m in Sources */,
13621365
5F909B5E23314CE900A774D2 /* BNCJSONUtilityTests.m in Sources */,
1366+
E74B54402D2DB0660049A89D /* BNCServerInterfaceTests.m in Sources */,
13631367
5F909B722332BEF600A774D2 /* BranchLastAttributedTouchDataTests.m in Sources */,
13641368
5FC20E732A93D85F00D9E1C8 /* BNCRequestFactoryTests.m in Sources */,
13651369
5FA9112F29BC662000F3D35C /* BNCNetworkInterfaceTests.m in Sources */,

Sources/BranchSDK/BNCServerInterface.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
177177

178178
- (BOOL)isLinkingRelatedRequest:(NSString *)endpoint postParams:(NSDictionary *)post {
179179

180-
BOOL hasIdentifier = (post[BRANCH_REQUEST_KEY_LINK_IDENTIFIER] != nil ) || (post[BRANCH_REQUEST_KEY_LINK_IDENTIFIER] != nil) || (post[BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL] != nil);
180+
BOOL hasIdentifier = (post[BRANCH_REQUEST_KEY_LINK_IDENTIFIER] != nil ) || (post[BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER] != nil) || (post[BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL] != nil);
181181

182182
// Allow install to resolve a link.
183183
if ([endpoint containsString:@"/v1/install"]) {

Sources/BranchSDK/Branch.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,18 +704,18 @@ - (void)initSessionWithLaunchOptions:(NSDictionary *)options
704704
self.shouldAutomaticallyDeepLink = automaticallyDisplayController;
705705

706706
// Check for Branch link in a push payload
707-
BranchOpenRequestLinkParams *params = [[BranchOpenRequestLinkParams alloc] init];
707+
BOOL appLaunchViaPushNotification = NO;
708708
#if !TARGET_OS_TV
709709
if ([options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) {
710710
id branchUrlFromPush = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey][BRANCH_PUSH_NOTIFICATION_PAYLOAD_KEY];
711711
if ([branchUrlFromPush isKindOfClass:[NSString class]]) {
712-
params.referringURL = (NSString *)branchUrlFromPush;
712+
appLaunchViaPushNotification = YES;
713713
}
714714
}
715715
#endif
716716

717-
if(params.referringURL || [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey]) ) {
718-
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlParams:params reset:NO];
717+
if( [[options objectForKey:@"BRANCH_DEFER_INIT_FOR_PLUGIN_RUNTIME_KEY"] isEqualToNumber:@1] || (![options.allKeys containsObject:UIApplicationLaunchOptionsURLKey] && ![options.allKeys containsObject:UIApplicationLaunchOptionsUserActivityDictionaryKey] && !appLaunchViaPushNotification)) {
718+
[self initUserSessionAndCallCallback:YES sceneIdentifier:nil urlParams:nil reset:NO];
719719
}
720720
}
721721

0 commit comments

Comments
 (0)