Keep live location shares when the location isn't found yet

Core Location reports CLError.locationUnknown when it can't get a fix
straight away and keeps trying, but didFailWithError stopped every
account's shares on any error. Ignore that one error and keep stopping
on real failures such as .denied.

Closes #6366
This commit is contained in:
Mauro Romito
2026-10-19 17:03:02 +02:00
committed by Mauro
parent 9bcb105d2b
commit 3e9f44e944
2 changed files with 35 additions and 0 deletions
@@ -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()
}
@@ -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,