mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-10-31 16:24:11 +00:00
Prevent the background task's expiration from stopping the main sync loop.
This commit is contained in:
@@ -26,8 +26,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
|
||||
/// Common background task to continue long-running tasks in the background.
|
||||
private var backgroundTask: UIBackgroundTaskIdentifier?
|
||||
|
||||
private var isSuspended = false
|
||||
|
||||
private var userSession: UserSessionProtocol? {
|
||||
didSet {
|
||||
@@ -929,8 +927,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
}
|
||||
}
|
||||
|
||||
isSuspended = true
|
||||
|
||||
// This does seem to work if scheduled from the background task above
|
||||
// Schedule it here instead but with an earliest being date of 30 seconds
|
||||
scheduleBackgroundAppRefresh()
|
||||
@@ -944,12 +940,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
appMediator.endBackgroundTask(backgroundTask)
|
||||
self.backgroundTask = nil
|
||||
}
|
||||
|
||||
if isSuspended {
|
||||
startSync()
|
||||
}
|
||||
|
||||
isSuspended = false
|
||||
|
||||
startSync()
|
||||
}
|
||||
|
||||
// MARK: Background app refresh
|
||||
@@ -989,7 +981,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
||||
scheduleBackgroundAppRefresh()
|
||||
|
||||
task.expirationHandler = { [weak self] in
|
||||
self?.stopSync() // Attempt to stop the sync loop cleanly.
|
||||
if UIApplication.shared.applicationState != .active {
|
||||
// Attempt to stop the sync loop cleanly, only if the app not already running
|
||||
self?.stopSync()
|
||||
}
|
||||
|
||||
MXLog.info("Background app refresh task expired")
|
||||
task.setTaskCompleted(success: true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user