I have a location based app running in swift. I am trying to detect if the self.locationManager.startUpdatingLocation()
is currently active.
I am struggling to find out how to do this nor can I find much on the internet about it. This I am fairly sure is rather simple to achieve. I don't want to set a BOOL as this needs to be global.
if CLLocationManager.locationServicesEnabled() && /* START UPDATE LOCATION GOES HERE */ {
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestAlwaysAuthorization()
self.locationManager.startUpdatingLocation()
//self.locationManager.startMonitoringSignificantLocationChanges()
sender.setTitle("END DAY", forState: UIControlState.Normal)
} else {
}
I know this is a late answer now. But this is possibly one solution if you want to know if the locationManager is updating.
There should only be one instance of CLLocationManager
in your app. So creating a Singleton is ideal. Then, you should override the methods startUpdatingLocation
and stopUpdatingLocation
.
(Swift 3)
import CoreLocation
class LocationManager: CLLocationManager {
var isUpdatingLocation = false
static let shared = LocationManager()
override func startUpdatingLocation() {
super.startUpdatingLocation()
isUpdatingLocation = true
}
override func stopUpdatingLocation() {
super.stopUpdatingLocation()
isUpdatingLocation = false
}
}
Usage:
if LocationManager.shared.isUpdatingLocation {
print("Is currently updating location.")
} else {
print("Location updates have stopped.")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With