Location updates in background…

Hello,

I’ve done a lot of testing of location services running in background with various settings, but in all scenarios location updates pause after a couple of hours, especially overnight In sleep mode.

My app, for personal safety, requires regular location updates to 5m accuracy every minute. The only solution I have found is to keep the app in foreground.

Location always stops updating. Background mode stops updating. Live location services stops updating.

Is there a solution I may have missed other than keeping app in foreground?

thank you, Brendan

Answered by Engineer in 841689022

Each CoreLocation API has their strengths and weaknesses.

Your best choice is going to be liveUpdates(), but that will stop updating if the device is not moving. When the updates stop, the .stationary property for the location update will be set, and then you can assume the location has not changed until the device moves and the location updates start flowing again.

If you use startUpdatingLocation(), that does not have the stop updates behavior, but is also less resilient to app crashes or the system/user terminating the app. If a crash or termination happens, the updates will not resume until the user launches the app again.

Another common reason we see for location updates stopping is, if you are taking too long to process the updates (e.g in didUpdateLocations()), and cannot keep up with the updates that arrive every second, at some point the system will stop sending location updates.

If you have too much you are doing in this callback function, or in some other way saturating or blocking the main thread, you could be blocking the incoming updates, and eventually they will stop.

You will want to start by debugging why the updates are stopping. Whether your app is crashing, being terminated by the system due to need for resources, or whether you are negatively effecting the delivery of location updates.


Argun Tekant /  DTS Engineer / Core Technologies

Accepted Answer

Each CoreLocation API has their strengths and weaknesses.

Your best choice is going to be liveUpdates(), but that will stop updating if the device is not moving. When the updates stop, the .stationary property for the location update will be set, and then you can assume the location has not changed until the device moves and the location updates start flowing again.

If you use startUpdatingLocation(), that does not have the stop updates behavior, but is also less resilient to app crashes or the system/user terminating the app. If a crash or termination happens, the updates will not resume until the user launches the app again.

Another common reason we see for location updates stopping is, if you are taking too long to process the updates (e.g in didUpdateLocations()), and cannot keep up with the updates that arrive every second, at some point the system will stop sending location updates.

If you have too much you are doing in this callback function, or in some other way saturating or blocking the main thread, you could be blocking the incoming updates, and eventually they will stop.

You will want to start by debugging why the updates are stopping. Whether your app is crashing, being terminated by the system due to need for resources, or whether you are negatively effecting the delivery of location updates.


Argun Tekant /  DTS Engineer / Core Technologies

Location updates in background…
 
 
Q