Skip to content

Commit 5a93956

Browse files
[SDK-2473] Fix for early branch init on install (#1451)
* Added networkCount reset for fixing early init.
1 parent 60ad084 commit 5a93956

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Branch-TestBed/Branch-TestBed/AppDelegate.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import "ViewController.h"
1313
#import "Branch.h"
1414
#import "BNCEncodingUtils.h"
15+
#import "BranchEvent.h"
1516

1617
AppDelegate* appDelegate = nil;
1718
void APPLogHookFunction(NSDate*_Nonnull timestamp, BranchLogLevel level, NSString*_Nullable message);
@@ -33,7 +34,6 @@ - (BOOL)application:(UIApplication *)application
3334

3435
// Branch.useTestBranchKey = YES; // Make sure to comment this line out for production apps!!!
3536
Branch *branch = [Branch getInstance];
36-
3737

3838
// Change the Branch base API URL
3939
//[Branch setAPIUrl:@"https://api3.branch.io"];
@@ -89,6 +89,12 @@ - (BOOL)application:(UIApplication *)application
8989
[self handleDeepLinkObject:universalObject linkProperties:linkProperties error:error];
9090
}];
9191

92+
93+
BranchEvent *earlyEvent = [BranchEvent standardEvent:BNCAddToCartEvent];
94+
NSLog(@"Logging Early Event: %@", earlyEvent);
95+
[earlyEvent logEvent];
96+
97+
9298
// Push notification support (Optional)
9399
// [self registerForPushNotifications:application];
94100

Sources/BranchSDK/Branch.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,7 +1931,9 @@ - (BOOL)isReplayableRequest:(BNCServerRequest *)request {
19311931

19321932
- (void)processNextQueueItem {
19331933
dispatch_semaphore_wait(self.processing_sema, DISPATCH_TIME_FOREVER);
1934-
1934+
1935+
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing next queue item. Network Count: %ld. Queue depth: %ld", (long)self.networkCount, (long)self.requestQueue.queueDepth] error:nil];
1936+
19351937
if (self.networkCount == 0 &&
19361938
self.requestQueue.queueDepth > 0) {
19371939

@@ -1943,10 +1945,11 @@ - (void)processNextQueueItem {
19431945

19441946
if (req) {
19451947

1946-
// If tracking is disabled, then do not check for install event. It won't exist.
1948+
// If tracking is disabled, then do not check for install event. It won't exist.
19471949
if (!Branch.trackingDisabled) {
19481950
if (![req isKindOfClass:[BranchInstallRequest class]] && !self.preferenceHelper.randomizedBundleToken) {
19491951
[[BranchLogger shared] logError:@"User session has not been initialized!" error:nil];
1952+
self.networkCount = 0;
19501953
BNCPerformBlockOnMainThreadSync(^{
19511954
[req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]];
19521955
});
@@ -1955,6 +1958,7 @@ - (void)processNextQueueItem {
19551958
} else if (![req isKindOfClass:[BranchOpenRequest class]] &&
19561959
(!self.preferenceHelper.randomizedDeviceToken || !self.preferenceHelper.sessionID)) {
19571960
[[BranchLogger shared] logError:@"Missing session items!" error:nil];
1961+
self.networkCount = 0;
19581962
BNCPerformBlockOnMainThreadSync(^{
19591963
[req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]];
19601964
});

0 commit comments

Comments
 (0)