iPhone Brainstorm - CLLocation in Background - Pol

2019-04-14 15:09发布

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.

3条回答
SAY GOODBYE
2楼-- · 2019-04-14 15:34

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楼-- · 2019-04-14 15:36

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

查看更多
太酷不给撩
4楼-- · 2019-04-14 15:47

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.

查看更多
登录 后发表回答