I am using CLServiceSession(authorization: .always)
to start a service session for tracking Zone entry and exit in the background in my app. It has been working fine on iOS 18 until recently when we added some BGProcessingTasks.
The task runs when the user is not moving and the device is on charge, this task runs fro a bit in the background, however we are seeing that even though we are reinitializing then session upon app launch.
We have even tried to just explicitly reinitialize a session within the background task callback, but the zone tracking still continues to fail. Significant location changes are unaffected.
Timeline of events:
- User Opens App,
- CLServiceSession(authorization: .always) is called (assume permissions have already been granted.)
- App is backgrounded
- User moves outside zone and app captures the data correctly (this can happen any amount of times)
- User plugs in Phone
- BGProcessingTask callback is run, it may or may not be terminated early. The service session is recreated as the first action in the callback. (we have also tried putting it in the main init() function for the app, same outcome)
- User moves outside zone later and app does NOT capture the data.
- User is sad :(
The session seems to be reinitialized correctly when the app is launched due to CoreLocation updates.
Is this expected behaviour or a bug? Is there a good way to debug what is happening with the sessions?
Unfortunately, the WWDC sessions on this have not enlightened us about the cause of this behaviour.