Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-2473] Fix for early branch init on install #1451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Branch-TestBed/Branch-TestBed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "ViewController.h"
#import "Branch.h"
#import "BNCEncodingUtils.h"
#import "BranchEvent.h"

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

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


// Change the Branch base API URL
//[Branch setAPIUrl:@"https://api3.branch.io"];
Expand Down Expand Up @@ -81,6 +81,12 @@ - (BOOL)application:(UIApplication *)application
[self handleDeepLinkObject:universalObject linkProperties:linkProperties error:error];
}];


BranchEvent *earlyEvent = [BranchEvent standardEvent:BNCAddToCartEvent];
NSLog(@"Logging Early Event: %@", earlyEvent);
[earlyEvent logEvent];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to queue an event before the sdk is initialized?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah



// Push notification support (Optional)
// [self registerForPushNotifications:application];

Expand Down
7 changes: 5 additions & 2 deletions Sources/BranchSDK/Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,9 @@ - (BOOL)isReplayableRequest:(BNCServerRequest *)request {

- (void)processNextQueueItem {
dispatch_semaphore_wait(self.processing_sema, DISPATCH_TIME_FOREVER);


[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing next queue item. Network Count: %ld. Queue depth: %ld", (long)self.networkCount, (long)self.requestQueue.queueDepth] error:nil];

if (self.networkCount == 0 &&
self.requestQueue.queueDepth > 0) {

Expand All @@ -1920,10 +1922,11 @@ - (void)processNextQueueItem {

if (req) {

// If tracking is disabled, then do not check for install event. It won't exist.
// If tracking is disabled, then do not check for install event. It won't exist.
if (!Branch.trackingDisabled) {
if (![req isKindOfClass:[BranchInstallRequest class]] && !self.preferenceHelper.randomizedBundleToken) {
[[BranchLogger shared] logError:@"User session has not been initialized!" error:nil];
self.networkCount = 0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be a thread safe operation? Can other areas be checking this value at the same time, and executing/not executing an event because of it? cc @NidhiDixit09

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gdeluna-branch networkCount is defined as a property and its protected using @synchronized (self) inside its accessor functions. So its thread safe.

@nsingh-branch I think we should add this fix for opens also. Its a rare case to happen but technically else if condition has the same issue.

BNCPerformBlockOnMainThreadSync(^{
[req processResponse:nil error:[NSError branchErrorWithCode:BNCInitError]];
});
Expand Down
Loading