iPhone 应用程序在屏幕锁定时运行
这是我拼命想要开始工作的事情:
我有一个应用程序,它以指定的时间间隔轮询 GPS 模块,然后使用 Unix 调用(例如 write())将坐标发送到服务器;当应用程序处于活动状态时,它工作正常,但一旦屏幕自行锁定,报告就会停止。
我发现了这个: [UIApplication sharedApplication].idleTimerDisabled = YES;这确实使应用程序保持活动状态,但也会快速耗尽电池电量。我遇到过其他即使在屏幕锁定时也能传输音乐的应用程序(非苹果应用程序),因此我认为必须有一种方法来保持 GPS 数据流的活动。
有人可以帮忙吗?谢谢你!
Here is something I am trying desperately to get to work:
I have an app that polls the GPS module in specified intervals and then sends out coords out to a server using Unix calls such as write(); It works fine when the app is active, but once the screen locks itself, reporting stops.
I have found this: [UIApplication sharedApplication].idleTimerDisabled = YES; This does keep the app alive, but also rapidly discharges the battery. I came across other apps that stream music even when the screen is locked (non-Apple apps) and thus I figured there has to be a way to keep the GPS data stream alive.
Can anyone assist? Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看看这个:
http:// /marcopeluso.com/2009/08/23/how-to-prevent-iphone-from-deep-sleeping/
这是用于禁用深度睡眠的代码片段。当您的应用程序继续在后台运行时,您的屏幕仍然可以关闭。
Have a look at this:
http://marcopeluso.com/2009/08/23/how-to-prevent-iphone-from-deep-sleeping/
It's a drop in piece of code used to disable deep sleep. Your screen can still shut off while your application continues to run in the background.
您必须保持屏幕解锁。但这并不意味着您必须启用 GPS。你可以关闭 GPS 监视器并每隔几分钟唤醒它,一分钟后出现的全黑“屏幕保护程序”应该会大大减少消耗。
You have to leave the screen unlocked. But that does not mean you have to leave GPS enabled. You can shut down the GPS monitor and awaken it every few minutes, that and an all-black "screensaver" that comes on after a minute should cut down on the drain quite a lot.
如果您的应用程序播放(或录制)声音,即使您播放静音,即使屏幕锁定,它也会继续运行。因此,您可能想尝试通过音频队列服务播放静音以保持应用程序运行。
请注意,我不知道关于这个问题的任何与 GPS 相关的细节。另一位评论者表示,当屏幕锁定时,GPS 被明确禁止运行(考虑到可能存在的隐私问题,这对苹果来说可能是一个明智的决定)。我无法建议这是否属实。
If your application plays (or records) sound, even if you play silence, it would continue running even when the screen is locked. So you might want to try to play silence via audio queue services to keep your app running.
Note that I don't know any GPS-related specifics with regards to this question. Another commenter says that GPS is specifically prohibited from running when the screen is locked (which might be a sensible decision on Apple's side, given the possible privacy issues). I can't advise whether that's true or not.
我不是 100% 确定,但我想我在某处听说 GPS 模块仅在屏幕未锁定时工作。 (当然,除非你有一部越狱的手机......)
我想我是在下载一个正在运行的应用程序时读到这篇文章的,该应用程序在我外出跑步时跟踪我的位置。该应用程序有自己的“锁定屏幕”,我必须安装它才能工作,这会很快耗尽电池电量。如果我正常锁定屏幕然后再次解锁,它必须重新获取我的位置。
I am not 100% sure, but I think I heard somewhere that the GPS module only works when the screen is not locked. (Unless you have a jailbroken phone of course...)
I think I read this when I was downloading a running application that kept track of my location while I was out running. The app had its own "lock screen" that I had to have up for it to work, which drained the battery quite fast. If I were to lock the screen normally then unlock it again, it would have to reacquire my location.
我认为这是不可能的(这是我过去一直想做的事情)。例如,我知道可以访问 GPS 的 safari 浏览器在屏幕锁定时不会这样做,尽管这可能是设计使然,而不是限制。
I don't think its possible (its something I've wanted to be able to do in the past). I know for instance that the safari browser, which can access GPS, doesn't do so when the screen is locked, although that could be by design rather than limitation.