Location "While in use" + Background?

I need some clarification on what is supposed to happen if the "allowsBackgroundLocationUpdates" flag on CLLocationManager is set to true, and only the "While in Use" permission has been given.

The customer I'm working with thinks that this combination should allow the app to receive location updates in the background indefinitely, as long as the app was in the foreground when we started receiving them.

What we've experienced is inconsistent. App updates do continue when the screen locks and in some cases when we switch to another app, but often they do not.

Our app doesn't require location updates 24/7, it requires them for a period of time when the user is performing an activity. The user starts and stops the activity in the app, and the activity might last up to a couple of hours. Can we do this using "While in Use" or do we need to request "Always" ?

I need some clarification on what is supposed to happen if the "allowsBackgroundLocationUpdates" flag on CLLocationManager is set to true, and only the "While in Use" permission has been given.

The customer I'm working with thinks that this combination should allow the app to receive location updates in the background indefinitely, as long as the app was in the foreground when we started receiving them.

Yes, that is correct, though how exactly it behaves depends on exactly how you're using the location service and what else your app is doing. The standard example of this usage model is a map app that's providing turn by turn directions.

What we've experienced is inconsistent. App updates do continue when the screen locks and in some cases when we switch to another app, but often they do not.

Our app doesn't require location updates 24/7, it requires them for a period of time when the user is performing an activity. The user starts and stops the activity in the app, and the activity might last up to a couple of hours. Can we do this using "While in Use" or do we need to request "Always" ?

Yes, this is possible (virtually all map apps do this), but there are also plenty of places where things can go wrong and your app suspends, ending the when in use session. Using turn by turn directions as an example, these apps tend to:

  • Monitor location with a stable configuration. One of the issues that often comes up is developers altering their monitoring configuration (often thinking it will save battery life) but instead ending their when in use session.

  • Include the "audio" background category and have an active audio session. Most apps doing this sort of thing some kind of information they need to communicate to the user and "playing audio" is the broadest solution to that issue. However, at a technical level, the audio system also provide an additional mechanism keeping there app awake, which helps "bridge" any disruption that might occur. Making that concrete, if something happens which causes CoreLocation to end it's own background assertion (the thing that keeps your app awake in the background) then the audio system will still keep your app awake, giving you enough time to resume monitoring withe CoreLocation.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Location "While in use" + Background?
 
 
Q