在多任务 iPhone 应用程序的后台运行 NSTimer 以打开/关闭位置服务

发布于 2024-09-12 21:24:47 字数 557 浏览 3 评论 0原文

我正在尝试制作一个每 10 分钟记录一次准确位置的应用程序。

这样做的问题是,当运行处于最佳模式时,电池电量消耗得非常快。

我想要一个计时器来关闭位置服务,让 didUpdateToLocation 获得一个好的位置,关闭位置服务,然后再次等待计时器。

我已经尝试了一百万件事 - 但我的 NSTimer 在进入后台模式时总是被冻结。

有趣的是,didUpdateFromLocation可以关闭位置服务,如果您使用significantChangeUpdate,您可以使用didUpdateToLocation在用户传递三角测量边界时重新打开位置服务 - 并将位置记录到coredata -

所以理论上,唯一阻止我运行这个东西的事情是一个线程中的 NSTimer,永远不会被冻结。

我读过一些文件,说你可以在后台做一些简单的事情,除了 VOIP、位置、音频之外。有谁有过让线程运行不被冻结的经验吗?我知道每个人都认为这是不可能的——根据我的研究,这是可能的,但我就是想不出来。

非常感谢基于任何经验的建议,让线程在 VOIP、音频、位置之外的后台运行,

谢谢大家,戴夫-

i am attempting to make an app that records an accurate location every 10 minutes.

the problem with this is that when running is best mode, the battery drains really quickly.

i would like a timer to turn of the location service, have didUpdateToLocation get a good location, turn of location service and then wait for the timer again.

i have tried a million things- but my NSTimer always gets frozen when put in background mode.

interestingly, didUpdateFromLocation can turn location service off, and if you use significantChangeUpdate you can use didUpdateToLocation to turn location service back on when the user passes a triangulation boundry- and record locations to coredata-

so in theory the only thing stopping me getting this thing running is an NSTimer in a thread that doesnt get frozen, ever.

i read some documents that said you CAN do simple things in the background beyond VOIP, location, audio. does anyone have any experience getting a thread running that doesnt get frozen? i know everyone thinks it can't be done- from my research it is possible, but i just cant figure it out.

advice based on any experience getting a thread running in the background beyond VOIP, Audio, location would be much appreciated

thanks guys, dave-

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

2024-09-19 21:24:47

这个问题的答案有一个替代方法,您可以使用重用applicationDidEnterBackground 事件自行循环,每次重新启动一个线程,您可以在其中做一些工作

iPhone - 后台轮询事件

The answer to this question has an alternative hack where you use re-use the applicationDidEnterBackground event to loop back on itself, each time re-starting a thread where you can do some work

iPhone - Backgrounding to poll for events

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文