Change to rely on application state instead of scanning scenes to determine if application is in background.

This commit is contained in:
Maurice Parker 2019-12-06 15:16:20 -07:00
parent 66c9d287bb
commit 90b9ab7851

View File

@ -54,15 +54,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
var isSyncArticleStatusRunning = false var isSyncArticleStatusRunning = false
var isWaitingForSyncTasks = 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() { override init() {
super.init() super.init()
appDelegate = self appDelegate = self
@ -234,7 +225,7 @@ private extension AppDelegate {
private extension AppDelegate { private extension AppDelegate {
func waitForSyncTasksToFinish() { func waitForSyncTasksToFinish() {
guard !isAnySceneInForeground && !isWaitingForSyncTasks else { return } guard !isWaitingForSyncTasks && UIApplication.shared.applicationState == .background else { return }
isWaitingForSyncTasks = true isWaitingForSyncTasks = true
@ -252,7 +243,7 @@ private extension AppDelegate {
} }
func waitToComplete(completion: @escaping (Bool) -> Void) { 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) os_log("App came back to forground, no longer waiting.", log: self.log, type: .info)
completion(false) completion(false)
return return
@ -302,7 +293,7 @@ private extension AppDelegate {
} }
func suspendApplication() { func suspendApplication() {
guard !isAnySceneInForeground else { return } guard UIApplication.shared.applicationState == .background else { return }
AccountManager.shared.suspendNetworkAll() AccountManager.shared.suspendNetworkAll()