Change to ensure that the app gets suspended when running too long during a background refresh.

This commit is contained in:
Maurice Parker 2019-12-02 14:44:52 -06:00
parent f159371967
commit 63428fb2a2
1 changed files with 4 additions and 1 deletions

View File

@ -301,12 +301,15 @@ private extension AppDelegate {
} }
func suspendApplication() { func suspendApplication() {
guard !isAnySceneInForeground else { return }
CoalescingQueue.standard.performCallsImmediately() CoalescingQueue.standard.performCallsImmediately()
for scene in UIApplication.shared.connectedScenes { for scene in UIApplication.shared.connectedScenes {
if let sceneDelegate = scene.delegate as? SceneDelegate { if let sceneDelegate = scene.delegate as? SceneDelegate {
sceneDelegate.suspend() sceneDelegate.suspend()
} }
} }
AccountManager.shared.saveAll()
AccountManager.shared.suspendAll() AccountManager.shared.suspendAll()
} }
@ -354,7 +357,6 @@ private extension AppDelegate {
AccountManager.shared.resumeAll() AccountManager.shared.resumeAll()
} }
AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) { [unowned self] in AccountManager.shared.refreshAll(errorHandler: ErrorHandler.log) { [unowned self] in
AccountManager.shared.saveAll()
self.suspendApplication() self.suspendApplication()
os_log("Account refresh operation completed.", log: self.log, type: .info) os_log("Account refresh operation completed.", log: self.log, type: .info)
task?.setTaskCompleted(success: true) task?.setTaskCompleted(success: true)
@ -363,6 +365,7 @@ private extension AppDelegate {
// set expiration handler // set expiration handler
task.expirationHandler = { [weak task] in task.expirationHandler = { [weak task] in
self.suspendApplication()
os_log("Accounts refresh processing terminated for running too long.", log: self.log, type: .info) os_log("Accounts refresh processing terminated for running too long.", log: self.log, type: .info)
task?.setTaskCompleted(success: false) task?.setTaskCompleted(success: false)
} }