From 90b9ab785188fb60b78a8fc6e1d4ad950a9737b9 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Fri, 6 Dec 2019 15:16:20 -0700 Subject: [PATCH] Change to rely on application state instead of scanning scenes to determine if application is in background. --- iOS/AppDelegate.swift | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/iOS/AppDelegate.swift b/iOS/AppDelegate.swift index 0f0daece9..41ab25b75 100644 --- a/iOS/AppDelegate.swift +++ b/iOS/AppDelegate.swift @@ -54,15 +54,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD var isSyncArticleStatusRunning = false var isWaitingForSyncTasks = false - var isAnySceneInForeground: Bool { - for scene in UIApplication.shared.connectedScenes { - if scene.activationState == .foregroundInactive || scene.activationState == .foregroundActive { - return true - } - } - return false - } - override init() { super.init() appDelegate = self @@ -234,7 +225,7 @@ private extension AppDelegate { private extension AppDelegate { func waitForSyncTasksToFinish() { - guard !isAnySceneInForeground && !isWaitingForSyncTasks else { return } + guard !isWaitingForSyncTasks && UIApplication.shared.applicationState == .background else { return } isWaitingForSyncTasks = true @@ -252,7 +243,7 @@ private extension AppDelegate { } func waitToComplete(completion: @escaping (Bool) -> Void) { - guard !isAnySceneInForeground else { + guard UIApplication.shared.applicationState == .background else { os_log("App came back to forground, no longer waiting.", log: self.log, type: .info) completion(false) return @@ -302,7 +293,7 @@ private extension AppDelegate { } func suspendApplication() { - guard !isAnySceneInForeground else { return } + guard UIApplication.shared.applicationState == .background else { return } AccountManager.shared.suspendNetworkAll()