Skip to content

Commit 332f4a7

Browse files
authored
DEVEX-850 iOS 12 Background Networking Change (#881)
* Added new network error check and updated queue handling for continueUserActivity. * Update unit test timing.
1 parent b51f893 commit 332f4a7

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

Branch-SDK-Tests/BNCServerRequestQueueTests.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ - (void)testCloseRequestsArentPersisted {
154154
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
155155
if ([reqs isKindOfClass:[NSArray class]]) {
156156
XCTAssert(reqs.count == 0);
157-
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
157+
BNCAfterSecondsPerformBlockOnMainThread(0.100, ^{
158158
[self safelyFulfillExpectation:expectation];
159159
});
160160
return YES;
@@ -170,7 +170,7 @@ - (void)testCloseRequestsArentPersisted {
170170
// Wait for operation to occur
171171
[self awaitExpectations];
172172
[archiverMock verify];
173-
BNCSleepForTimeInterval(0.001); // Allow for mock class to be un-mocked.
173+
BNCSleepForTimeInterval(0.500); // Allow for mock class to be un-mocked.
174174
}
175175
}
176176

@@ -184,7 +184,7 @@ - (void)testDebugRequestsArentPersisted {
184184
archivedDataWithRootObject:[OCMArg checkWithBlock:^BOOL(NSArray *reqs) {
185185
if ([reqs isKindOfClass:[NSArray class]]) {
186186
XCTAssert(reqs.count == 0);
187-
BNCAfterSecondsPerformBlockOnMainThread(0.01, ^{
187+
BNCAfterSecondsPerformBlockOnMainThread(0.100, ^{
188188
[self safelyFulfillExpectation:expectation];
189189
});
190190
return YES;
@@ -198,7 +198,7 @@ - (void)testDebugRequestsArentPersisted {
198198
// Wait for operation to occur
199199
[self awaitExpectations];
200200
[archiverMock verify];
201-
BNCSleepForTimeInterval(0.001); // Allow for mock class to be un-mocked.
201+
BNCSleepForTimeInterval(0.500); // Allow for mock class to be un-mocked.
202202
}
203203
}
204204

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -848,14 +848,9 @@ - (BOOL)continueUserActivity:(NSUserActivity *)userActivity {
848848

849849
// Check to see if a browser activity needs to be handled
850850
if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
851-
852851
// If we're already in-progress cancel the last open and do this one.
853-
BOOL isNewSession = NO;
854-
if (![self removeInstallOrOpen]) {
855-
isNewSession = YES;
856-
}
857-
858-
return [self handleDeepLink:userActivity.webpageURL fromSelf:isNewSession];
852+
[self removeInstallOrOpen];
853+
return [self handleDeepLink:userActivity.webpageURL fromSelf:YES];
859854
}
860855

861856
// Check to see if a spotlight activity needs to be handled

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,11 @@ - (void)genericHTTPRequest:(NSURLRequest *)request
551551
// indicating various parts of the HTTP post failed.
552552
// We should retry in those conditions in addition to the case where the server returns a 500
553553

554-
BOOL isRetryableStatusCode = status >= 500 || status < 0;
554+
// Status 53 means the request was killed by the OS because we're still in the background.
555+
// This started happening in iOS 12 / Xcode 10 production when we're called from continueUserActivity:
556+
// but we're not fully out of the background yet.
557+
558+
BOOL isRetryableStatusCode = status >= 500 || status < 0 || status == 53;
555559

556560
// Retry the request if appropriate
557561
if (retryNumber < self.preferenceHelper.retryCount && isRetryableStatusCode) {

Examples/UITestBed/UITestBed/TBAppDelegate.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ - (BOOL)application:(UIApplication *)application
127127
userActivity.webpageURL.absoluteString);
128128
// Required. Returns YES if Branch Universal Link, else returns NO.
129129
// Add `branch_universal_link_domains` to .plist (String or Array) for custom domain(s).
130+
[[Branch getInstance] userCompletedAction:@"Open Universal Link"];
130131
[[Branch getInstance] continueUserActivity:userActivity];
131132

132133
// Process non-Branch userActivities here...

0 commit comments

Comments
 (0)