2

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?

4

1 に答える 1

1

これは非常によく聞かれる質問ですが、残念ながら、バックグラウンドでの実行がいつ、どのように行われるかを正確に制御することはできません。

startMonitoringSignificantLocationChangesデバイスが約500 m移動したときの更新のみが正しい場合の質問については、ドキュメントに記載されており、おそらく読んでいます:)

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.
于 2014-11-03T16:21:10.800 に答える