3

I'm building a running-based app in Swift that requests the user's location. For the sake of this question, let's just assume the app runs only on iOS 13+. Shortly after launching the app, we prompt the user for location access via the CLLocationManager method: requestWhenInUseAuthorization().

However, this app actually needs access to the user's location all the time, so only being able to request "When In Use" location access (per iOS 13) restricts the UX (other apps like Zenly and Snapchat do this as well since getting constant location updates improves the experience for their users and/or their friends).

After prompting for the location permission, we then grab the latest location authorization status. If that value is not equal to authorizedAlways (and it won't be unless the user changes that value in his/her Settings app), we present a new screen basically telling the user, "Since this is a running app, we really need your location all the time, so please go to settings and change the permission to 'Always' since we can't do it for you."

The issue I'm running into here is that when listening for updates on the CLLocationManagerDelegate method: locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus), sometimes that method provides the incorrect location authorization status.

Specifically, after a user selects "When In Use" and runs the app a few times, the value returned from that delegate method frequently reads as "Always," even though the Settings app on the phone still reflects the original, unchanged value ("When In Use").

Has anyone run into this before and, if so, do you have any ideas on what might cause it or how to fix it? Happy to provide more info on my setup. Thanks.

Brian Sachetta
  • 3,319
  • 2
  • 34
  • 45
  • 1
    You can request always, but it functions as "when in use" while you have provisional always until the user changes your permission. You don't provide details in your app, but chances are you don't really need always, what you need is when in use with background. If you do need always then it is best if you ask for that and let ios prompt the user to upgrade your access later – Paulw11 Nov 12 '19 at 21:36
  • Thanks for the comment. "Provisional always" was definitely what I was looking for, though it seems as though in that "provisional always" state, the app functions as "always" despite showing "while in use" in Settings. This WWDC video I found since posting sums it up well (especially right at the 4:23 mark): https://developer.apple.com/videos/play/wwdc2019/705/ – Brian Sachetta Nov 12 '19 at 22:10
  • 1
    That is correct. You ask for always, the user sees a request for “when in use”. If the user approves then your app gets told it has “always” but it behaves like “when in use”. If your app does the right things, such as setting background location requests or using significant location change monitoring then the user will subsequently be prompted to upgrade your access to always or leave it as when in use. – Paulw11 Nov 12 '19 at 22:13

0 Answers0