Dynamic Location Tracking using CLServiceSession and CLBackgroundActivitySession

Hello,

I'm currently implementing code to track routes and determine if users have arrived at their destination using CLServiceSession, CLBackgroundActivitySession, and CLLocationUpdate.liveUpdates.

I want to obtain location data across all app states: foreground, background, and terminated. I have two questions:

  1. Background Location Indicator Issue: I'm using CLBackgroundActivitySession to get location updates in the background. Normally, the background location indicator (blue bar) doesn't appear at the top left of the screen for my app. However, when another app (e.g., LiveUpdatesSample) activates CLBackgroundActivitySession, my app's background location indicator suddenly becomes visible. Can you explain why this happens? or Can I Control showsBackgroundLocationIndicator in CLBackgroundActivitySession

  2. Session Management: Is there a way to terminate all currently active CLBackgroundActivitySessions? I understand that when CLBackgroundActivitySession is activated and the app is terminated and then relaunched, a new CLBackgroundActivitySession needs to be created. In this case, are the previously created and running CLBackgroundActivitySessions automatically released when the app is relaunched?

  1. Dynamic Configuration Updates: I want to implement a feature that minimizes location tracking when the user is far from the destination and increases tracking detail as they get closer. How can I change the configuration of currently running liveUpdates regardless of the app state? Does changing the configuration affect the location update frequency?

Why doesn't the background location indicator disappear even after calling CLBackgroundActivitySession.invalidate()?

1. Background Location Indicator Issue: The blue location indicator only appears for apps that do not have Always authorization, but have an active background location session while only have obtained When-In-Use authorization. And is meant to alert the user that an app without background location authorization is accessing their location in the background.

There is only a single blue indicator, so I don't understand what you mean by my app's background location indicator suddenly becomes visible.

If by that you mean when you tap the indicator your app opens up instead of the other app, that behavior is not deterministic, and if there are multiple apps tracking location, any one of them can open when the indicator is tapped.

2. Session Management: There isn't a way to just invalidate all sessions. You must call invalidate() on each of them separately.

When your app is terminated, all in memory objects, including CLBackgroundActivitySession objects are released.

3. Dynamic Configuration Updates: You can use CLLocationUpdate.LiveConfiguration to change the types of updates, but this will not change the rate of the updates.

4. Invalidate issue: Calling invalidate() will end the session immediately and if you have a blue location indicator tied to that session, that will also disappear.

If this is not happening, make sure you are invalidating the correct CLBackgroundActivitySession if you have more than one (as you have implied above)

  1. Dynamic Configuration Updates: So currently, there's no way to change the update frequency like CLLocationManager, is there?

Why does an alert with "has used your location times in the background" appear even though the app has "Always Allow" authorization?

Is the alert only shown when making excessive location requests?

In the new API, the updates are constant unless the device is stationary. then they stop (with the .stationary flag). And they resume when there is movement again.

The "has used your location" alert appears BECAUSE you have Always authorization. As long as you are receiving locations while in the background, the alert will periodically appear.

It will appear regardless of excessive requests. It will appear more if there are excessive requests.

The alert cannot be avoided outside of not receiving location when the app is in the background.

Dynamic Location Tracking using CLServiceSession and CLBackgroundActivitySession
 
 
Q