Skip to content

Commit

Permalink
Better 0198 compatibility and slightly longer background timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Aug 10, 2016
1 parent bf8406e commit a1d81f0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ChatSecure/Classes/OTRAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,17 @@ - (void)applicationDidEnterBackground:(UIApplication *)application
}];

dispatch_async(dispatch_get_main_queue(), ^{
self.backgroundTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES];
self.backgroundTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES];
});
}

- (void) timerUpdate:(NSTimer*)timer {
UIApplication *application = [UIApplication sharedApplication];

DDLogInfo(@"Timer update, background time left: %f", application.backgroundTimeRemaining);
NSTimeInterval timeRemaining = application.backgroundTimeRemaining;
DDLogVerbose(@"Timer update, background time left: %f", timeRemaining);

if ([application backgroundTimeRemaining] < 60 && !self.didShowDisconnectionWarning && [OTRSettingsManager boolForOTRSettingKey:kOTRSettingKeyShowDisconnectionWarning])
if (timeRemaining < 60 && !self.didShowDisconnectionWarning && [OTRSettingsManager boolForOTRSettingKey:kOTRSettingKeyShowDisconnectionWarning])
{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif) {
Expand All @@ -329,15 +330,15 @@ - (void) timerUpdate:(NSTimer*)timer {
}
self.didShowDisconnectionWarning = YES;
}
if ([application backgroundTimeRemaining] < 15)
if (timeRemaining < 3)
{
// Clean up here
[self.backgroundTimer invalidate];
self.backgroundTimer = nil;

[[OTRProtocolManager sharedInstance] disconnectAllAccounts];
[[OTRProtocolManager sharedInstance] disconnectAllAccountsSocketOnly:YES];

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(8 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[application endBackgroundTask:self.backgroundTask];
self.backgroundTask = UIBackgroundTaskInvalid;
});
Expand Down

0 comments on commit a1d81f0

Please sign in to comment.