improve the location stuff

This commit is contained in:
Stephen B 2026-02-25 16:15:24 -05:00
parent b61fecb630
commit 1bdf72ac2f
5 changed files with 25 additions and 8 deletions

View file

@ -10,6 +10,7 @@ final class BackgroundLocationManager: NSObject, CLLocationManagerDelegate {
private let locationManager = CLLocationManager()
private var isRunning = false
private var activityCount = 0
private override init() {
super.init()
@ -39,6 +40,20 @@ final class BackgroundLocationManager: NSObject, CLLocationManagerDelegate {
locationManager.stopUpdatingLocation()
}
func requestStart() {
activityCount += 1
if activityCount == 1, UserDefaults.standard.bool(forKey: "keepAliveLocation") {
start()
}
}
func requestStop() {
activityCount = max(activityCount - 1, 0)
if activityCount == 0 {
stop()
}
}
func locationManagerDidChangeAuthorization(_ manager: CLLocationManager) {
guard isRunning else { return }
switch manager.authorizationStatus {