Make sure screen protection is applied before ending bg task

* code cleanup
* Prefer dispatch_async vs. dispatch_sync when possible

// FREEBIE
pull/1/head
Michael Kirk 8 years ago
parent ab9b9833d5
commit 2c7ccbe5db

@ -414,27 +414,21 @@ static NSString *const kURLHostVerifyPrefix = @"verify";
- (void)applicationWillResignActive:(UIApplication *)application { - (void)applicationWillResignActive:(UIApplication *)application {
DDLogWarn(@"%@ applicationWillResignActive.", self.tag); DDLogWarn(@"%@ applicationWillResignActive.", self.tag);
UIBackgroundTaskIdentifier __block bgTask = UIBackgroundTaskInvalid;
bgTask = [application beginBackgroundTaskWithExpirationHandler:^{
}];
UIBackgroundTaskIdentifier bgTask = [application beginBackgroundTaskWithExpirationHandler:nil];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
if ([TSAccountManager isRegistered]) { if ([TSAccountManager isRegistered]) {
dispatch_sync(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) {
// If app has not re-entered active, show screen protection if necessary. // If app has not re-entered active, show screen protection if necessary.
[self showScreenProtection]; [self showScreenProtection];
} }
[[[Environment getCurrent] signalsViewController] updateInboxCountLabel]; [[[Environment getCurrent] signalsViewController] updateInboxCountLabel];
}); [application endBackgroundTask:bgTask];
} });
}
[application endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}); });
[DDLog flushLog]; [DDLog flushLog];
} }

Loading…
Cancel
Save