From a6370d2c79a9d25f0e328fe2537231f6cc9754b6 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 26 Apr 2019 14:03:59 -0500 Subject: [PATCH] Remove code duplication in background fetch. --- iOS/AppDelegate.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 1b6354ddd..49f145de8 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -142,12 +142,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele os_log("Woken to perform account refresh.", log: log, type: .info) let startingUnreadCount = unreadCount - let updateCompletionHandler = { [unowned self] in + + let completeProcessing = { [unowned self] in + + UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask) + self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid + if startingUnreadCount != self.unreadCount { completionHandler(.newData) } else { completionHandler(.noData) } + } AccountManager.shared.refreshAll() @@ -157,9 +163,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele DispatchQueue.global(qos: .background).async { [unowned self] in self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask { - UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask) - self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - updateCompletionHandler() + completeProcessing() } sleep(1) @@ -168,12 +172,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele sleep(1) } + completeProcessing() os_log("Accounts completed refresh processing.", log: self.log, type: .info) - UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask) - self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - updateCompletionHandler() - } }