diff --git a/ElementX/Sources/Services/Location/LiveLocationManager.swift b/ElementX/Sources/Services/Location/LiveLocationManager.swift index e06147780..f8abd46d5 100644 --- a/ElementX/Sources/Services/Location/LiveLocationManager.swift +++ b/ElementX/Sources/Services/Location/LiveLocationManager.swift @@ -115,6 +115,12 @@ final class LiveLocationManager: NSObject, LiveLocationManagerProtocol, CLLocati } func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) { + // Core Location keeps trying after this one, so the shares can carry on. + if (error as? CLError)?.code == .locationUnknown { + MXLog.info("Location manager couldn't find the location yet") + return + } + MXLog.error("Location manager failed with error: \(error)") stopAllLiveLocations() } diff --git a/UnitTests/Sources/LiveLocationManagerTests.swift b/UnitTests/Sources/LiveLocationManagerTests.swift index c9e83dbae..ff8b24cee 100644 --- a/UnitTests/Sources/LiveLocationManagerTests.swift +++ b/UnitTests/Sources/LiveLocationManagerTests.swift @@ -158,6 +158,35 @@ final class LiveLocationManagerTests { #expect(appSettings.hasRequestedLocationAlwaysLocationAuthorization) } + // MARK: - Errors + + @Test + func notFindingTheLocationYetKeepsTheShares() async { + setUp() + let alice = makeService(userID: "@alice:matrix.org", isSharing: .init(true)) + manager.add(alice) + + await waitForConfirmation("The shares keep running", expectedCount: 0, timeout: .milliseconds(500)) { confirm in + alice.stopAllLiveLocationsClosure = { confirm() } + manager.locationManager(CLLocationManager(), didFailWithError: CLError(.locationUnknown)) + } + } + + @Test + func otherLocationErrorsStopEveryAccountsShares() async { + setUp() + let alice = makeService(userID: "@alice:matrix.org", isSharing: .init(true)) + let bob = makeService(userID: "@bob:matrix.org", isSharing: .init(true)) + manager.add(alice) + manager.add(bob) + + await waitForConfirmation("Wait for the shares to stop", expectedCount: 2) { confirm in + alice.stopAllLiveLocationsClosure = { confirm() } + bob.stopAllLiveLocationsClosure = { confirm() } + manager.locationManager(CLLocationManager(), didFailWithError: CLError(.denied)) + } + } + // MARK: - Private private func setUp(authorizationStatus: CLAuthorizationStatus = .authorizedAlways,