Skip to content

Commit 353a1f7

Browse files
authored
Merge pull request #1351 from BranchMetrics/INTENG-19264
INTENG-19264 and INTENG-19577 bug fixes
2 parents cde01b3 + e561653 commit 353a1f7

File tree

10 files changed

+123
-217
lines changed

10 files changed

+123
-217
lines changed

Branch-TestBed/Branch-SDK-Tests/BNCRequestFactoryTests.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ - (void)tearDown {
2525

2626
- (void)testInitWithBranchKeyNil {
2727
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:nil];
28-
NSDictionary *json = [factory dataForInstall];
28+
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
2929
XCTAssertNotNil(json);
3030

3131
// key is omitted when nil
@@ -34,7 +34,7 @@ - (void)testInitWithBranchKeyNil {
3434

3535
- (void)testInitWithBranchKeyEmpty {
3636
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@""];
37-
NSDictionary *json = [factory dataForInstall];
37+
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
3838
XCTAssertNotNil(json);
3939

4040
// empty string is allowed
@@ -43,14 +43,14 @@ - (void)testInitWithBranchKeyEmpty {
4343

4444
- (void)testInitWithBranchKey {
4545
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
46-
NSDictionary *json = [factory dataForInstall];
46+
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
4747
XCTAssertNotNil(json);
4848
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
4949
}
5050

5151
- (void)testDataForInstall {
5252
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
53-
NSDictionary *json = [factory dataForInstall];
53+
NSDictionary *json = [factory dataForInstallWithURLString:@"https://branch.io"];
5454
XCTAssertNotNil(json);
5555

5656
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
@@ -64,7 +64,7 @@ - (void)testDataForInstall {
6464

6565
- (void)testDataForOpen {
6666
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
67-
NSDictionary *json = [factory dataForOpen];
67+
NSDictionary *json = [factory dataForOpenWithURLString:@"https://branch.io"];
6868
XCTAssertNotNil(json);
6969

7070
XCTAssertTrue([@"key_abcd" isEqualToString:[json objectForKey:@"branch_key"]]);
@@ -182,13 +182,13 @@ - (void)testDataForEventNil {
182182

183183
- (void)testDataForShortURL {
184184
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
185-
NSDictionary *json = [factory dataForInstall];
185+
NSDictionary *json = [factory dataForShortURLWithLinkDataDictionary:@{}.mutableCopy isSpotlightRequest:NO];
186186
XCTAssertNotNil(json);
187187
}
188188

189189
- (void)testDataForLATD {
190190
BNCRequestFactory *factory = [[BNCRequestFactory alloc] initWithBranchKey:@"key_abcd"];
191-
NSDictionary *json = [factory dataForInstall];
191+
NSDictionary *json = [factory dataForLATDWithDataDictionary:@{}.mutableCopy];
192192
XCTAssertNotNil(json);
193193
}
194194

Sources/BranchSDK/BNCRequestFactory.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ - (BOOL)isTrackingDisabled {
7676
return Branch.trackingDisabled;
7777
}
7878

79-
- (NSDictionary *)dataForInstall {
79+
- (NSDictionary *)dataForInstallWithURLString:(NSString *)urlString {
8080
NSMutableDictionary *json = [NSMutableDictionary new];
8181

8282
// All requests
@@ -100,6 +100,10 @@ - (NSDictionary *)dataForInstall {
100100
[self addAppleReceiptSourceToJSON:json];
101101
[self addTimestampsToJSON:json];
102102

103+
if (urlString) {
104+
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
105+
}
106+
103107
[self addAppleAttributionTokenToJSON:json];
104108

105109
// Install Only
@@ -116,7 +120,7 @@ - (NSDictionary *)dataForInstall {
116120
return json;
117121
}
118122

119-
- (NSDictionary *)dataForOpen {
123+
- (NSDictionary *)dataForOpenWithURLString:(NSString *)urlString {
120124
NSMutableDictionary *json = [NSMutableDictionary new];
121125

122126
// All requests
@@ -143,6 +147,10 @@ - (NSDictionary *)dataForOpen {
143147
[self addAppleReceiptSourceToJSON:json];
144148
[self addTimestampsToJSON:json];
145149

150+
if (urlString) {
151+
[self safeSetValue:urlString forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
152+
}
153+
146154
// Usually sent with install, but retry on open if it didn't get sent
147155
[self addAppleAttributionTokenToJSON:json];
148156

@@ -279,7 +287,6 @@ - (void)addPreferenceHelperDataToJSON:(NSMutableDictionary *)json {
279287

280288
[self safeSetValue:self.preferenceHelper.linkClickIdentifier forKey:BRANCH_REQUEST_KEY_LINK_IDENTIFIER onDict:json];
281289
[self safeSetValue:self.preferenceHelper.spotlightIdentifier forKey:BRANCH_REQUEST_KEY_SPOTLIGHT_IDENTIFIER onDict:json];
282-
[self safeSetValue:self.preferenceHelper.universalLinkUrl forKey:BRANCH_REQUEST_KEY_UNIVERSAL_LINK_URL onDict:json];
283290
[self safeSetValue:self.preferenceHelper.initialReferrer forKey:BRANCH_REQUEST_KEY_INITIAL_REFERRER onDict:json];
284291

285292
// This was only on opens before, cause it can't exist on install.

Sources/BranchSDK/BNCServerRequestQueue.m

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -161,56 +161,17 @@ - (BOOL)containsInstallOrOpen {
161161
}
162162
}
163163

164-
- (BOOL)removeInstallOrOpen {
164+
- (BranchOpenRequest *)findExistingInstallOrOpen {
165165
@synchronized (self) {
166166
for (NSUInteger i = 0; i < self.queue.count; i++) {
167167
BNCServerRequest *request = [self.queue objectAtIndex:i];
168-
// Install extends open, so only need to check open.
169-
if ([request isKindOfClass:[BranchOpenRequest class]]) {
170-
[[BranchLogger shared] logDebug:@"Removing open request."];
171-
((BranchOpenRequest *)request).callback = nil;
172-
[self remove:request];
173-
return YES;
174-
}
175-
}
176-
return NO;
177-
}
178-
}
179-
180-
- (BranchOpenRequest *)moveInstallOrOpenToFront:(NSInteger)networkCount {
181-
@synchronized (self) {
182-
183-
BOOL requestAlreadyInProgress = networkCount > 0;
184168

185-
BNCServerRequest *openOrInstallRequest;
186-
for (NSUInteger i = 0; i < self.queue.count; i++) {
187-
BNCServerRequest *req = [self.queue objectAtIndex:i];
188-
if ([req isKindOfClass:[BranchOpenRequest class]]) {
189-
190-
// Already in front, nothing to do
191-
if (i == 0 || (i == 1 && requestAlreadyInProgress)) {
192-
return (BranchOpenRequest *)req;
193-
}
194-
195-
// Otherwise, pull this request out and stop early
196-
openOrInstallRequest = [self removeAt:i];
197-
break;
169+
// Install subclasses open, so only need to check open
170+
if ([request isKindOfClass:[BranchOpenRequest class]]) {
171+
return (BranchOpenRequest *)request;
198172
}
199173
}
200-
201-
if (!openOrInstallRequest) {
202-
[[BranchLogger shared] logError:@"No install or open request in queue while trying to move it to the front." error:nil];
203-
return nil;
204-
}
205-
206-
if (!requestAlreadyInProgress || !self.queue.count) {
207-
[self insert:openOrInstallRequest at:0];
208-
}
209-
else {
210-
[self insert:openOrInstallRequest at:1];
211-
}
212-
213-
return (BranchOpenRequest *)openOrInstallRequest;
174+
return nil;
214175
}
215176
}
216177

0 commit comments

Comments
 (0)