iPhone 头脑风暴 - CLLocation 在后台 - 每 15 分钟轮询一次
这是场景。我需要一个应用程序,它每 15 分钟轮询一次 Web 服务,无论是在后台还是前台。
目前我:
- 启动/重新启动位置管理器,精度最高,距离过滤器无。
- 等待达到所需的精度。
- 将读数 setDesiredAccuracy 存储
- 为:“kCLLocationAccuracyThreeKilometers”
- setDistanceFilter 为:1000
- 设置 PerformSelector:@selector(getLocation) withObject:nil afterDelay:900
- 从步骤 1 重新开始。
我想让这成为最节省电池的方法,并希望看看其他堆叠者对上述选项的看法以及你们是否有任何其他建议。
谢谢 詹姆斯.
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:
- Start / Restart the location manager with accuracy highest and distance filter none.
- Wait to get within desired accurancy.
- Store reading
- setDesiredAccuracy to be: "kCLLocationAccuracyThreeKilometers"
- setDistanceFilter to be: 1000
- Set a performSelector:@selector(getLocation) withObject:nil afterDelay:900
- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您的目标不是 iOS3,请考虑使用“重大更改”API,它对于这种情况应该是最有效的。
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.
为什么不注册该应用程序以进行重大位置更改并直接使用它呢?很多应用程序都可以(包括我的一些应用程序),而且它非常省电。事实上,除非手机进行手机信号塔切换,否则什么都不会发生。如果手机在某个地方放置几个小时,实际上不会对电池产生影响。在您的方法中,整个 CL 框架和 GPS 硬件必须每 15 分钟启动一次。
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.
最后,我让应用程序在执行选择器:WithDelay 上每 15 分钟启动/停止位置管理器。
基本上,当 CLLocationManager 给出所需精度内的读数时,我降低 CLLocation 以表示更改,然后将应用程序设置为 15 分钟后再次读取,将精度更改为最高设置之一并重复。
希望这对将来的任何人都有帮助。
谢谢
詹姆斯
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