@@ -72,11 +72,10 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
7272
7373
7474@property (strong , nonatomic ) BNCServerInterface *bServerInterface;
75- @property (strong , nonatomic ) NSTimer *sessionTimer;
7675@property (strong , nonatomic ) BNCServerRequestQueue *requestQueue;
7776@property (strong , nonatomic ) dispatch_semaphore_t processing_sema;
78- @property (strong , nonatomic ) callbackWithParams sessionInitWithParamsCallback;
79- @property (strong , nonatomic ) callbackWithBranchUniversalObject sessionInitWithBranchUniversalObjectCallback;
77+ @property (copy , nonatomic ) callbackWithParams sessionInitWithParamsCallback;
78+ @property (copy , nonatomic ) callbackWithBranchUniversalObject sessionInitWithBranchUniversalObjectCallback;
8079@property (assign , nonatomic ) NSInteger networkCount;
8180@property (assign , nonatomic ) BOOL isInitialized;
8281@property (assign , nonatomic ) BOOL shouldCallSessionInitCallback;
@@ -86,15 +85,15 @@ @interface Branch() <BranchDeepLinkingControllerCompletionDelegate, FABKit>
8685@property (strong , nonatomic ) BNCContentDiscoveryManager *contentDiscoveryManager;
8786@property (strong , nonatomic ) NSString *branchKey;
8887@property (strong , nonatomic ) NSMutableDictionary *deepLinkControllers;
89- @property (weak , nonatomic ) UIViewController *deepLinkPresentingController;
88+ @property (weak , nonatomic ) UIViewController *deepLinkPresentingController;
9089@property (assign , nonatomic ) BOOL useCookieBasedMatching;
9190@property (strong , nonatomic ) NSDictionary *deepLinkDebugParams;
9291@property (assign , nonatomic ) BOOL accountForFacebookSDK;
9392@property (assign , nonatomic ) id FBSDKAppLinkUtility;
9493@property (assign , nonatomic ) BOOL delayForAppleAds;
9594@property (assign , nonatomic ) BOOL searchAdsDebugMode;
9695@property (strong , nonatomic ) NSMutableArray *whiteListedSchemeList;
97-
96+ @property ( assign , nonatomic ) BOOL appIsInBackground;
9897@end
9998
10099@implementation Branch
@@ -1152,6 +1151,7 @@ - (BNCLinkData *)prepareLinkDataFor:(NSArray *)tags andAlias:(NSString *)alias a
11521151
11531152#pragma mark - BranchUniversalObject methods
11541153
1154+
11551155- (void )registerViewWithParams : (NSDictionary *)params andCallback : (callbackWithParams)callback {
11561156 [self initSessionIfNeededAndNotInProgress ];
11571157
@@ -1164,22 +1164,18 @@ - (void)registerViewWithParams:(NSDictionary *)params andCallback:(callbackWithP
11641164#pragma mark - Application State Change methods
11651165
11661166- (void )applicationDidBecomeActive {
1167- [ self clearTimer ] ;
1167+ self. appIsInBackground = NO ;
11681168 if (!self.isInitialized && !self.preferenceHelper .shouldWaitForInit && ![self .requestQueue containsInstallOrOpen ]) {
11691169 [self initUserSessionAndCallCallback: YES ];
11701170 }
11711171}
11721172
11731173- (void )applicationWillResignActive {
1174- [ self clearTimer ] ;
1175- self. sessionTimer = [ NSTimer scheduledTimerWithTimeInterval: 0.5 target: self selector: @selector ( callClose ) userInfo: nil repeats: NO ];
1174+ self. appIsInBackground = YES ;
1175+ [ self callClose ];
11761176 [self .requestQueue persistImmediately ];
11771177}
11781178
1179- - (void )clearTimer {
1180- [self .sessionTimer invalidate ];
1181- }
1182-
11831179- (void )callClose {
11841180 if (self.isInitialized ) {
11851181 self.isInitialized = NO ;
@@ -1268,11 +1264,7 @@ - (void)processNextQueueItem {
12681264 [req processResponse: nil error: [NSError errorWithDomain: BNCErrorDomain code: BNCInitError userInfo: @{ NSLocalizedDescriptionKey : @" Branch User Session has not been initialized" }]];
12691265 return ;
12701266 }
1271-
1272- if (![req isKindOfClass: [BranchCloseRequest class ]]) {
1273- [self clearTimer ];
1274- }
1275-
1267+
12761268 [req makeRequest: self .bServerInterface key: self .branchKey callback: callback];
12771269 }
12781270 }
@@ -1338,26 +1330,17 @@ - (void)registerInstallOrOpen:(Class)clazz {
13381330 if ([BNCSystemObserver getOSVersion ].integerValue >= 9 && self.useCookieBasedMatching ) {
13391331 [[BNCStrongMatchHelper strongMatchHelper ] createStrongMatchWithBranchKey: self .branchKey];
13401332 }
1341-
1342- // If there isn't already an Open / Install request, add one to the queue
1343- if (![self .requestQueue containsInstallOrOpen ]) {
1344- BranchOpenRequest *req = [[clazz alloc ] initWithCallback: initSessionCallback];
1345-
1346- [self insertRequestAtFront: req];
1347- }
1348- // If there is already one in the queue, make sure it's in the front.
1349- // Make sure a callback is associated with this request. This callback can
1350- // be cleared if the app is terminated while an Open/Install is pending.
1351- else {
1352- BranchOpenRequest *req = [self .requestQueue moveInstallOrOpenToFront: self .networkCount];
1353- req.callback = initSessionCallback;
1354- }
1355-
1333+
1334+ if ([self .requestQueue removeInstallOrOpen ])
1335+ self.networkCount = 0 ;
1336+ BranchOpenRequest *req = [[clazz alloc ] initWithCallback: initSessionCallback];
1337+ [self insertRequestAtFront: req];
13561338 [self processNextQueueItem ];
13571339}
13581340
13591341- (void )handleInitSuccess {
1360- self.isInitialized = YES ;
1342+ if (!self.appIsInBackground )
1343+ self.isInitialized = YES ;
13611344
13621345 NSDictionary *latestReferringParams = [self getLatestReferringParams ];
13631346 if (self.shouldCallSessionInitCallback ) {
@@ -1436,4 +1419,4 @@ + (NSString *)kitDisplayVersion {
14361419 return @" 0.12.16" ;
14371420}
14381421
1439- @end
1422+ @end
0 commit comments