From 2c7ccbe5dbae80c544648d98bb91f6a2481b829a Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Thu, 25 May 2017 07:34:55 -0700 Subject: [PATCH] Make sure screen protection is applied before ending bg task * code cleanup * Prefer dispatch_async vs. dispatch_sync when possible // FREEBIE --- Signal/src/AppDelegate.m | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/Signal/src/AppDelegate.m b/Signal/src/AppDelegate.m index 11bb86009..58ea73f60 100644 --- a/Signal/src/AppDelegate.m +++ b/Signal/src/AppDelegate.m @@ -414,27 +414,21 @@ static NSString *const kURLHostVerifyPrefix = @"verify"; - (void)applicationWillResignActive:(UIApplication *)application { 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), ^{ - if ([TSAccountManager isRegistered]) { - dispatch_sync(dispatch_get_main_queue(), ^{ - if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { - // If app has not re-entered active, show screen protection if necessary. - [self showScreenProtection]; - } - [[[Environment getCurrent] signalsViewController] updateInboxCountLabel]; - }); - } - - [application endBackgroundTask:bgTask]; - bgTask = UIBackgroundTaskInvalid; + if ([TSAccountManager isRegistered]) { + dispatch_async(dispatch_get_main_queue(), ^{ + if ([UIApplication sharedApplication].applicationState != UIApplicationStateActive) { + // If app has not re-entered active, show screen protection if necessary. + [self showScreenProtection]; + } + [[[Environment getCurrent] signalsViewController] updateInboxCountLabel]; + [application endBackgroundTask:bgTask]; + }); + } }); - + [DDLog flushLog]; }