What conditions make iOS 13 to ask user to grant 'Always' location access?

Viewed 1345

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'.

screenshot 1

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'

see screenshot 2

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!

3 Answers

@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()

I believe that's the new iOS 13 behaviour, here it is stated that

If your app requests and receives When In Use authorization, you can make a separate request for Always authorization later. However, apps may make only one request for Always authorization.

Also for reference you can check this thread

This is the new iOS 13 behaviour. This has been implemented by apple to give users more transparency. For a detailed understanding of this change you can refer to this link

Related