CLLocationmanager: Save battery

南楼画角 提交于 2020-01-03 17:25:18

问题


My new "app in progress" uses an instance of CLLocationManager for several purposes. To make the app as battery-friendly as possible, the location services should be activated only if needed, and deactivated immediately when the data refresh is done. For my purpose it's perfectly enough to fetch the location data only once in 10 seconds. (Haven't yet decided the exact interval length).

My question is, which is the most battery-efficient method of "turning off the Location services"? Is it sufficient to just use the "stopUpdatingLocation" method and keep the CLLocationManager himself in memory, or am I required to release the entire instance, and allocate a new one before the next refresh?


回答1:


I agree with the other answers that stopUpdatingLocation in combination with the distanceFilter and desiredAccuracy is the way to go. Note that when the desired accuracy is in the scope of kilometres, the location manager might not even have to fire up the GPS.

Similarly, depending on what you use it for, have a look at region monitoring and significant location updates since those are more battery friendly.

Related: Location Awareness Programming Guide - Tips for Conserving Battery Power




回答2:


Yes. Calling stopUpdatingLocation is enough.

Better way is to set good values for distanceFilter and desiredAccuracy. 10secs is not enough time to warm up the gps.

CLLocationManager




回答3:


Setting appropriate distanceFilter and desiredAccuracy are probably the two factors that have the most impact on you battery life.

However

To really know what is the most battery-friendly you should use Instruments and measure the battery drain on the device. There is a built-in tool for that.



来源:https://stackoverflow.com/questions/10470036/cllocationmanager-save-battery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!