mirror of
https://github.com/StikDebug/StikDebug.git
synced 2026-10-16 04:20:30 +00:00
improve the location stuff
This commit is contained in:
parent
b61fecb630
commit
1bdf72ac2f
5 changed files with 25 additions and 8 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue