I am using CLLocationUpdate.liveUpdates()
to build a location sharing app. Most of the time it works fine, including in the background, giving acceptably frequent updates. However, soon after the user puts their phone away for the night, the updates stop coming.
I've checked all the instance properties (.stationary, .locationUnavailable, etc.) but none of them are ever set to true, even for the last update before updates end.
Is there some way to keep the updates coming through the night?
I've included some relevant parts of my code here:
func startLocationUpdates() {
if self.manager.authorizationStatus == .notDetermined {
self.manager.requestWhenInUseAuthorization()
}
Task {
do {
self.background = CLBackgroundActivitySession()
self.session = CLServiceSession(authorization: CLServiceSession.AuthorizationRequirement.always)
let updates = CLLocationUpdate.liveUpdates()
for try await update in updates {
if let loc = update.location {
BackgroundServiceKt.onLocationUpdate(arg: loc)
}
// check all the instance properties
}
} catch {
// error
}
return
}
}
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
LocationsHandler.shared.startLocationUpdates()
return true
}
}