@@ -561,7 +561,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
561
561
562
562
showLoadingIndicator ( )
563
563
564
- stopSync ( )
564
+ stopSync ( isBackgroundTask : false )
565
565
userSessionFlowCoordinator? . stop ( )
566
566
567
567
guard !isSoft else {
@@ -748,7 +748,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
748
748
749
749
navigationRootCoordinator. setRootCoordinator ( PlaceholderScreenCoordinator ( ) )
750
750
751
- stopSync ( )
751
+ stopSync ( isBackgroundTask : false )
752
752
userSessionFlowCoordinator? . stop ( )
753
753
754
754
let userID = userSession. clientProxy. userID
@@ -848,7 +848,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
848
848
849
849
// MARK: - Application State
850
850
851
- private func stopSync( ) {
851
+ private func stopSync( isBackgroundTask: Bool ) {
852
+ if isBackgroundTask, UIApplication . shared. applicationState == . active {
853
+ // Attempt to stop the background task sync loop cleanly, only if the app not already running
854
+ return
855
+ }
852
856
userSession? . clientProxy. stopSync ( )
853
857
clientProxyObserver = nil
854
858
}
@@ -911,7 +915,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
911
915
912
916
@objc
913
917
private func applicationWillTerminate( ) {
914
- stopSync ( )
918
+ stopSync ( isBackgroundTask : false )
915
919
}
916
920
917
921
@objc
@@ -930,7 +934,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
930
934
backgroundTask = appMediator. beginBackgroundTask { [ weak self] in
931
935
guard let self else { return }
932
936
933
- stopSync ( )
937
+ stopSync ( isBackgroundTask : true )
934
938
935
939
if let backgroundTask {
936
940
appMediator. endBackgroundTask ( backgroundTask)
@@ -988,10 +992,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
988
992
scheduleBackgroundAppRefresh ( )
989
993
990
994
task. expirationHandler = { [ weak self] in
991
- if UIApplication . shared. applicationState != . active {
992
- // Attempt to stop the sync loop cleanly, only if the app not already running
993
- self ? . stopSync ( )
994
- }
995
+ self ? . stopSync ( isBackgroundTask: true )
995
996
996
997
MXLog . info ( " Background app refresh task expired " )
997
998
task. setTaskCompleted ( success: true )
@@ -1015,7 +1016,7 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg
1015
1016
1016
1017
// Make sure we stop the sync loop, otherwise the ongoing request is immediately
1017
1018
// handled the next time the app refreshes, which can trigger timeout failures.
1018
- stopSync ( )
1019
+ stopSync ( isBackgroundTask : true )
1019
1020
backgroundRefreshSyncObserver? . cancel ( )
1020
1021
1021
1022
task. setTaskCompleted ( success: true )
0 commit comments