mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-24 18:59:36 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user