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!
“Always Allow” meaning an app could be collecting your real-time location both while the app was visible on the screen AND in the background even when the app was not visible on the screen. “Don't Allow” meaning that apps could never collect your real-time location.
To request authorization, call requestWhenInUseAuthorization or requestAlwaysAuthorization , depending on the authorization status your app needs. See Choosing the Location Services Authorization to Request for more information about deciding what type of authorization to request.
Maps & Travel: Navigation apps require your location for turn-by-turn directions, and most travel apps use your location to help you find cool places nearby. Plus, ride-sharing apps (like Uber and Lyft) use your location, so drivers know where to pick you up.
@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()
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