Is there a way to trigger the .always coreLocation permission proactively in iOS13?
When you request a user for their "Always" location permission in iOS 13:
locationManager.requestAlwaysAuthorization()
1) The user will get this alert:
2) If you asked for always permission and your user chooses Allow While in Use
your app will think it got the .authorizedAlways
permission but this is the provisional .authorizedAlways
permission.
3) Next, when your app would normally receive location events in the background iOS does not directly launches your app in the background with the events but waits until it thinks the user is not doing anything and it then will present this dialog:
According to the video, this can take a while (6:39):
The prompt that the user can grant your app always authorization from will occur later. {...} Core Location waits for a time when we think that the user is not busy in order to maximize their ability to understand what's going on and minimize the chance that they'll give a get-out-of-my-way kind of response.
During this this (in between the app going to the background and the prompt being shown) you won't receive location update events:
They'll be delivered if you app receives always authorization ultimately and not if it receives a when in use authorization. But they also won't be delivered if the user just hasn't chosen yet.
So, during this time, if more events are generated on that basis, if you're monitoring requests, then those events will displace the ones that came earlier, and the earlier ones will be dropped. And then finally Core Location will drop the event part for anything that's become just too old.
4) Then when the user chooses Change to Always Allow
, the .authorizedAlways
permission will become final (unless the user changes it from the settings somewhere in the future). And you will start to receive location events.
Unless (5) the user chooses Keep Only While Using
and the final permission will become .authorizedWhenInUse
.
Here's the overview from the presentation (numbers mine):
And another link to the full video: https://developer.apple.com/videos/play/wwdc2019/705
Does that answer your questions?
If I change manually the permission setting to a real .always permission for my app, the app continues to be unable to range locations in the background.
That should not be the case. Did you change it in the system preferences?
Try the GM seed, maybe they fixed some bugs regarding this flow.
To see the second dialog with the Allow Always
prompt you have to:
- Disable the blue indicator.
- Go to the background.
- Wait at least 5 seconds.
- Try to get a location update or use any other core location service.
- Wait until the user locks and unlocks the device.
To facilitate this, you can set the distance filter to none and start getting continuous location updates.
If you want the location updates to be delivered in the background, then you have to show the blue indicator. And then the second dialog requesting Allow Always
would never appear.