Core functionality of my app is updating location data in background mode. In iOS 13, when we calling locationManager.requestAlwaysAuthorization()
, system asks user to choose among variants 'Never'
, 'Permit Once'
and 'When in use'
.
If user grants 'When in use'
access, our app will be able to work only in foreground.
The thing i can't understand is following:
Sometimes when app goes into background and after a while became active and goes into background again, iOS 13 asks user to change location access to 'Always'
What should my app to do to make iOS 13 to show this dialog to user? (I want to do it, when my app goes into background at first time)
P.S. I know, i can use some custom alert with text like "please, go to system settings and adjust location access for this app to 'Always' mode". But i need to know, is there any way to use "native system flow" as described above?
Thanks!
@Claudio's answer helps me to solve my problem. I've found that it is able to access location in background having 'When in use'
permission. To do so, you must set locationManager.showsBackgroundLocationIndicator = true
.
Here is my locationManager adjustment:
let locationManager = CLLocationManager()
if #available(iOS 9, *){
locationManager.allowsBackgroundLocationUpdates = true
}
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.headingFilter = kCLHeadingFilterNone
locationManager.pausesLocationUpdatesAutomatically = true
locationManager.activityType = .otherNavigation
if #available(iOS 11.0, *) {
locationManager.showsBackgroundLocationIndicator = true;
}
locationManager.delegate = self
locationManager.startMonitoringSignificantLocationChanges()