diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index dfab253da..201dcef5a 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -1106,6 +1106,16 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg selector: #selector(applicationWillResignActive), name: UIApplication.willResignActiveNotification, object: nil) + + NotificationCenter.default.addObserver(self, + selector: #selector(applicationDidEnterBackground), + name: UIApplication.didEnterBackgroundNotification, + object: nil) + + NotificationCenter.default.addObserver(self, + selector: #selector(applicationWillEnterForeground), + name: UIApplication.willEnterForegroundNotification, + object: nil) NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive), name: UIApplication.didBecomeActiveNotification, @@ -1128,17 +1138,23 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg @objc private func applicationWillTerminate() { + MXLog.info("Application will terminate") stopSync(isBackgroundTask: false) } @objc - private func applicationWillResignActive() { - MXLog.info("Application will resign active") - + private func applicationDidEnterBackground() { + MXLog.info("Application did enter background") + scheduleDelayedSyncStop() scheduleBackgroundAppRefresh() } + @objc + private func applicationWillResignActive() { + MXLog.info("Application will resign active") + } + private func scheduleDelayedSyncStop() { guard backgroundTask == nil else { return @@ -1157,12 +1173,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg } @objc - private func applicationDidBecomeActive() { - MXLog.info("Application did become active") + private func applicationWillEnterForeground() { + MXLog.info("Application will enter foreground") endActiveBackgroundTask() startSync() } + @objc + private func applicationDidBecomeActive() { + MXLog.info("Application did become active") + } + private func endActiveBackgroundTask() { guard let backgroundTask else { return