I would like to get the blue bar when tracking in the background, but not when not.
My app uses location services all the time when active, so in iOS8 I use the
To show blue notification you need to add Privacy - Location When In Use Usage Description in Plist file (this is important, with Always Location the blue bar didn´t appear ever)
self.locationManager.delegate = self;
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.pausesLocationUpdatesAutomatically = true/false
self.locationManager.allowsBackgroundLocationUpdates = true
then star the location: locationManager.startUpdatingLocation()
Also override methods:
func locationManager(_ manager: CLLocationManager, didUpdateLocations
locations: [CLLocation]) {
print(manager.location?.coordinate.latitude ?? "No data")
}
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse {
if CLLocationManager.isMonitoringAvailable(for: CLBeaconRegion.self) {
if CLLocationManager.isRangingAvailable() {
// do stuff
print(manager.location?.coordinate.latitude ?? "No data")
locationManager.startUpdatingLocation()
}
}
}
}
Remember the import!!:
import CoreLocation
And also remember the Delegate (CLLocationManagerDelegate):
class ViewController: UIViewController, CLLocationManagerDelegate{