iPhone Brainstorm - CLLocation in Background - Polling every 15 minutes

荒凉一梦 提交于 2019-12-06 10:47:36

问题


Here is the scenario. I need to have an application which polls a web service with the users location every 15 minutes whether in background / foreground.

At the moment I:

  1. Start / Restart the location manager with accuracy highest and distance filter none.
  2. Wait to get within desired accurancy.
  3. Store reading
  4. setDesiredAccuracy to be: "kCLLocationAccuracyThreeKilometers"
  5. setDistanceFilter to be: 1000
  6. Set a performSelector:@selector(getLocation) withObject:nil afterDelay:900
  7. Start again from step 1.

I want to make this the most battery saving method possible and would like to see what fellow 'stackers think of the option above and if you guys have any other suggestions.

Thanks James.


回答1:


If you're not targetting iOS3, consider using the 'significant change' API, it's supposed to be the most efficient for this kind of scenario.




回答2:


Why not register the app for significant location change and just use that? Plenty of apps do (including some of mine) and it's quite battery-friendly. In fact, NOTHING HAPPENS unless the phone does a cell tower hand-off. If the phone sits somewhere for hours, there's literally NO battery impact. In your approach the whole CL framework and the GPS hardware has to fire up every 15 minutes.




回答3:


In the end I got the application to start / stop the location manager every 15 minutes on a performSelector: WithDelay.

Basically when the CLLocationManager gave a reading within the desired accuracy I lowered the CLLocation to significate changes then set the application to take another reading 15 minutes later, changed the accuracy to one of the highest settings and repeated.

Hope this helps anyone in the future. Thanks James



来源:https://stackoverflow.com/questions/6099589/iphone-brainstorm-cllocation-in-background-polling-every-15-minutes

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