diff --git a/ElementX/Sources/Application/AppCoordinator.swift b/ElementX/Sources/Application/AppCoordinator.swift index 012f248f1..71ee3f073 100644 --- a/ElementX/Sources/Application/AppCoordinator.swift +++ b/ElementX/Sources/Application/AppCoordinator.swift @@ -148,6 +148,8 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg switch action { case .startCall(let roomID): self?.handleAppRoute(.call(roomID: roomID)) + case .receivedIncomingCallRequest: + self?.scheduleDelayedSyncStop() default: break } @@ -912,6 +914,11 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg private func applicationWillResignActive() { MXLog.info("Application will resign active") + scheduleDelayedSyncStop() + scheduleBackgroundAppRefresh() + } + + private func scheduleDelayedSyncStop() { guard backgroundTask == nil else { return } @@ -926,10 +933,6 @@ class AppCoordinator: AppCoordinatorProtocol, AuthenticationFlowCoordinatorDeleg self.backgroundTask = nil } } - - // 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() } @objc diff --git a/ElementX/Sources/Services/ElementCall/ElementCallService.swift b/ElementX/Sources/Services/ElementCall/ElementCallService.swift index 95e804d97..1ecf1dfa2 100644 --- a/ElementX/Sources/Services/ElementCall/ElementCallService.swift +++ b/ElementX/Sources/Services/ElementCall/ElementCallService.swift @@ -170,11 +170,13 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe // https://stackoverflow.com/a/41230020/730924 update.remoteHandle = .init(type: .generic, value: roomID) - callProvider.reportNewIncomingCall(with: callID.callKitID, update: update) { error in + callProvider.reportNewIncomingCall(with: callID.callKitID, update: update) { [weak self] error in if let error { MXLog.error("Failed reporting new incoming call with error: \(error)") } + self?.actionsSubject.send(.receivedIncomingCallRequest) + completion() } diff --git a/ElementX/Sources/Services/ElementCall/ElementCallServiceProtocol.swift b/ElementX/Sources/Services/ElementCall/ElementCallServiceProtocol.swift index 1247541e5..63bdd0c78 100644 --- a/ElementX/Sources/Services/ElementCall/ElementCallServiceProtocol.swift +++ b/ElementX/Sources/Services/ElementCall/ElementCallServiceProtocol.swift @@ -8,6 +8,7 @@ import Combine enum ElementCallServiceAction { + case receivedIncomingCallRequest case startCall(roomID: String) case endCall(roomID: String) case setAudioEnabled(_ enabled: Bool, roomID: String)