mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Improve Application lifetime scheduling
We have noticed race conditions between deep link handling and client resuming/sync starting which lead to timelines being created without being able to access the underlying stores. This patch switches to foreground/background app tracking in an attempt at a cheap way to fix the underlying issue. Arguably this was the correct way to do it to being with.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user