In our app we have the necessity to gather background location after a trigger from a bluetooth event.
During the onboarding we ask for authorizedWhenInUse
.
CLLocationManager
is configured like this, and in capabilities we provided the location
flag.
let cl = CLLocationManager()
cl.delegate = self
cl.allowsBackgroundLocationUpdates = true
cl.desiredAccuracy = kCLLocationAccuracyBestForNavigation
According to apple doc or at least what I understood, this should be enough to obtain locations even when the app is in background (and awake).
The system allows background updates for apps with either When in Use or Always authorization. If an app isn't running when an update occurs, the system launches the app only if it has Always authorization and uses the significant location change, visits, or region monitoring services.
We saw an inconsistent bahviour, the system request to start the location updates after the bluetooth event (we have background capabilities set also for that). In foreground it work always, but in background sometimes it works and sometimes not.
When we don't receive a location we usually get a CLError.denied
in the
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)
method.
At this point I don't get the apple doc quote, is it possible to obtain location in background or not with authorizedWhenInUse
?