views:

1298

answers:

5

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!

A: 

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.

Ian Kremer
A: 

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.

mbehan
+1  A: 

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.

Kendall Helmstetter Gelner
Kendall, can you please expand on your suggestion?If I leave the screen unlocked using [UIApplication sharedApplication].idleTimerDisabled = YES; this at least for me keeps the screen and the BG light on, thus the battery is bleeding heavily. Is there any other way to keep the screen unlocked, but shut the BG light off?
David
I don't think there's any way to disable the BG light. The thinking was that the battery drain might be lessened if the screen held minimal data so no other work was being done by the system to keep images on screen.
Kendall Helmstetter Gelner
+1  A: 

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.

Andrey Tarantsov
+3  A: 

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.

MrWiggles