Search code examples
iosobjective-cxcodecllocationmanagerbackground-task

Background Location


I need to track the user's location in the background at a specific time. Can the background task be started at e.g 7pm-11pm?

The only way I have been able to acheive this so far is to have the background task continually running and this seems a bad approach as it considerably drains battery.

I have set the accuracy and distance filter of the CLLocation manager to conserve battery outside of these times:

[locationManager setDesiredAccuracy:kCLLocationAccuracyThreeKilometers];
[locationManager setDistanceFilter:2000.0f];

I then change this between 7-11pm back to:

[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDistanceFilter:10.0f];

I have turned off locationManager.pausesLocationUpdatesAutomatically as this seems to kill the background task when the user stays still for 15-20mins - it doesn't resume when the user moves again.

Is there a better way to minimise battery drain outside of these times.

Also, am I correct in thinking that startMonitoringSignificantLocationChanges only does a location update when you move over 500m - if this is the case it would not be accurate enough during 7-11pm.

Any ideas?


Solution

  • This is quite a common question to be asked, and the short answer unfortunately is that you don't have the possibility to precisely control when and how your background execution takes place.

    About your question if startMonitoringSignificantLocationChanges only updates when the device moves about 500 m is also correct, it is stated in the docs, which you probably read :)

    The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.