Adding a safeguard to startNewSessionIfNeeded and removing safeguard that never helped anyone as appBackgroundTimeBeforeSessionExpires is always 20!

This commit is contained in:
Benjamin Scholtysik (Reimold)
2016-09-06 21:31:33 -07:00
parent 2a85e65652
commit 3cec0a380d

View File

@@ -122,15 +122,12 @@ static NSString *const BITMetricsURLPathString = @"v2/track";
}
- (void)startNewSessionIfNeeded {
if (self.appBackgroundTimeBeforeSessionExpires == 0) {
__weak typeof(self) weakSelf = self;
dispatch_async(_metricsEventQueue, ^{
typeof(self) strongSelf = weakSelf;
[strongSelf startNewSessionWithId:bit_UUID()];
});
}
double appDidEnterBackgroundTime = [self.userDefaults doubleForKey:kBITApplicationDidEnterBackgroundTime];
// Add safeguard in case this returns a negative value
if(appDidEnterBackgroundTime < 0) {
appDidEnterBackgroundTime = 0;
[self.userDefaults setDouble:0 forKey:kBITApplicationDidEnterBackgroundTime];
}
double timeSinceLastBackground = [[NSDate date] timeIntervalSince1970] - appDidEnterBackgroundTime;
if (timeSinceLastBackground > self.appBackgroundTimeBeforeSessionExpires) {
[self startNewSessionWithId:bit_UUID()];