From 7392d6111aed049b2ed813e1ed8b8ffeed0a606f Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 26 Apr 2019 09:42:00 -0500 Subject: [PATCH] Update to accurately report if data was received during background fetch or not. --- iOS/AppDelegate.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index f9bdf9512..1b6354ddd 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -141,6 +141,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele os_log("Woken to perform account refresh.", log: log, type: .info) + let startingUnreadCount = unreadCount + let updateCompletionHandler = { [unowned self] in + if startingUnreadCount != self.unreadCount { + completionHandler(.newData) + } else { + completionHandler(.noData) + } + } + AccountManager.shared.refreshAll() os_log("Accounts requested to begin refresh.", log: self.log, type: .debug) @@ -150,7 +159,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele self.backgroundUpdateTask = UIApplication.shared.beginBackgroundTask { UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask) self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - completionHandler(.newData) + updateCompletionHandler() } sleep(1) @@ -163,12 +172,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele UIApplication.shared.endBackgroundTask(self.backgroundUpdateTask) self.backgroundUpdateTask = UIBackgroundTaskIdentifier.invalid - completionHandler(.newData) - + updateCompletionHandler() + } - completionHandler(.newData) - } // MARK: - Split view