@@ -73,6 +73,7 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
7373
7474@property (strong , nonatomic ) BNCServerInterface *bServerInterface;
7575@property (strong , nonatomic ) BNCServerRequestQueue *requestQueue;
76+ @property (strong , nonatomic ) NSTimer *sessionTimer;
7677@property (strong , nonatomic ) dispatch_semaphore_t processing_sema;
7778@property (copy , nonatomic ) callbackWithParams sessionInitWithParamsCallback;
7879@property (copy , nonatomic ) callbackWithBranchUniversalObject sessionInitWithBranchUniversalObjectCallback;
@@ -93,7 +94,6 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
9394@property (assign , nonatomic ) BOOL delayForAppleAds;
9495@property (assign , nonatomic ) BOOL searchAdsDebugMode;
9596@property (strong , nonatomic ) NSMutableArray *whiteListedSchemeList;
96- @property (assign , nonatomic ) BOOL appIsInBackground;
9797@end
9898
9999@implementation Branch
@@ -1181,15 +1181,15 @@ - (void)registerViewWithParams:(NSDictionary *)params andCallback:(callbackWithP
11811181#pragma mark - Application State Change methods
11821182
11831183- (void )applicationDidBecomeActive {
1184- self. appIsInBackground = NO ;
1184+ [ self clearTimer ] ;
11851185 if (!self.isInitialized && !self.preferenceHelper .shouldWaitForInit && ![self .requestQueue containsInstallOrOpen ]) {
11861186 [self initUserSessionAndCallCallback: YES ];
11871187 }
11881188}
11891189
11901190- (void )applicationWillResignActive {
1191- self. appIsInBackground = YES ;
1192- [ self callClose ];
1191+ [ self clearTimer ] ;
1192+ self. sessionTimer = [ NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector ( callClose ) userInfo: nil repeats: NO ];
11931193 [self .requestQueue persistImmediately ];
11941194}
11951195
@@ -1211,6 +1211,9 @@ - (void)callClose {
12111211 }
12121212}
12131213
1214+ - (void )clearTimer {
1215+ [self .sessionTimer invalidate ];
1216+ }
12141217
12151218#pragma mark - Queue management
12161219
@@ -1282,6 +1285,10 @@ - (void)processNextQueueItem {
12821285 return ;
12831286 }
12841287
1288+ if (![req isKindOfClass: [BranchCloseRequest class ]]) {
1289+ [self clearTimer ];
1290+ }
1291+
12851292 dispatch_queue_t queue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0 );
12861293 dispatch_async (queue, ^ {
12871294 [req makeRequest: self .bServerInterface key: self .branchKey callback: callback];
@@ -1359,8 +1366,7 @@ - (void)registerInstallOrOpen:(Class)clazz {
13591366}
13601367
13611368- (void )handleInitSuccess {
1362- if (!self.appIsInBackground )
1363- self.isInitialized = YES ;
1369+ self.isInitialized = YES ;
13641370
13651371 NSDictionary *latestReferringParams = [self getLatestReferringParams ];
13661372 if (self.shouldCallSessionInitCallback ) {
0 commit comments