mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 01:20:12 +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),
|
selector: #selector(applicationWillResignActive),
|
||||||
name: UIApplication.willResignActiveNotification,
|
name: UIApplication.willResignActiveNotification,
|
||||||
object: nil)
|
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,
|
NotificationCenter.default.addObserver(self,
|
||||||
selector: #selector(applicationDidBecomeActive),
|
selector: #selector(applicationDidBecomeActive),
|
||||||
name: UIApplication.didBecomeActiveNotification,
|
name: UIApplication.didBecomeActiveNotification,
|
||||||
@@ -1128,17 +1138,23 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func applicationWillTerminate() {
|
private func applicationWillTerminate() {
|
||||||
|
MXLog.info("Application will terminate")
|
||||||
stopSync(isBackgroundTask: false)
|
stopSync(isBackgroundTask: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func applicationWillResignActive() {
|
private func applicationDidEnterBackground() {
|
||||||
MXLog.info("Application will resign active")
|
MXLog.info("Application did enter background")
|
||||||
|
|
||||||
scheduleDelayedSyncStop()
|
scheduleDelayedSyncStop()
|
||||||
scheduleBackgroundAppRefresh()
|
scheduleBackgroundAppRefresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
private func applicationWillResignActive() {
|
||||||
|
MXLog.info("Application will resign active")
|
||||||
|
}
|
||||||
|
|
||||||
private func scheduleDelayedSyncStop() {
|
private func scheduleDelayedSyncStop() {
|
||||||
guard backgroundTask == nil else {
|
guard backgroundTask == nil else {
|
||||||
return
|
return
|
||||||
@@ -1157,12 +1173,17 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
private func applicationDidBecomeActive() {
|
private func applicationWillEnterForeground() {
|
||||||
MXLog.info("Application did become active")
|
MXLog.info("Application will enter foreground")
|
||||||
endActiveBackgroundTask()
|
endActiveBackgroundTask()
|
||||||
startSync()
|
startSync()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
private func applicationDidBecomeActive() {
|
||||||
|
MXLog.info("Application did become active")
|
||||||
|
}
|
||||||
|
|
||||||
private func endActiveBackgroundTask() {
|
private func endActiveBackgroundTask() {
|
||||||
guard let backgroundTask else {
|
guard let backgroundTask else {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user