PDA

View Full Version : Determining when iPhone has gone to "sleep"?




bignumbers
Jul 15, 2008, 04:52 PM
I've written an app which uses a timer. Never mind the details but every second the app beeps. Works fine.

The iPhone (at least the display) goes to "sleep" after some period of time, 30 seconds maybe. When my app is running, the display sleeps, but my app keeps beeping away.

Is there a way to find out when the iPhone has gone to sleep so I can stop processing?

(When I click the Home button to wake the iPhone, the app quits properly. I'd like it to at least halt/pause or even quit on this "sleep" event.)

Thanks!



bignumbers
Jul 15, 2008, 05:14 PM
Never mind - found it:

applicationWillResignActive:

Now I just need to figure out how to use it!

iphonehere
Aug 7, 2008, 02:35 PM
Actually I wanted to have a timer to be running after it gone to "sleep" mode.

But it seems the timer was suspended once the phone in "sleep" mode.

So how do you keep your app running in the sleep mode?

Thanks.

SwampThingTom
Aug 7, 2008, 02:44 PM
So how do you keep your app running in the sleep mode?

You can't. Apple doesn't allow apps to run in the background.

Tom

iphonehere
Aug 7, 2008, 02:48 PM
So here is the question:
How does aol radio and pandora play in sleep mode? (They do, I verified more than 10 times.)

And how can bignumbers make his beep in sleep mode?

Is this only for audio apps?

Thanks a lot.


You can't. Apple doesn't allow apps to run in the background.

Tom

Garrett
Aug 7, 2008, 03:38 PM
You can't. Apple doesn't allow apps to run in the background.

Tom

You sure speak like thats the answer. :cool:

Apps do run in the backround. I made a test application to test it. When it resigns, it records the time. When it becomes active from resign, it gets the new timestamp. I also NSLog every 5 seconds while in sleep.

You can't run an app while running another application. Thats what "running in the background means". Else Last.fm would add a scrobbler.

SwampThingTom
Aug 7, 2008, 03:57 PM
It does appear that audio can continue playing after an app exits. I haven't fooled around with audio so I can't comment on how this works.

But I do know that no apps continue to run in the background. I've played with several techniques to try to work around this restriction to no avail... ;-)

Tom

SwampThingTom
Aug 7, 2008, 03:59 PM
You sure speak like thats the answer. :cool:

Apps do run in the backround. I made a test application to test it. When it resigns, it records the time. When it becomes active from resign, it gets the new timestamp. I also NSLog every 5 seconds while in sleep.

You can't run an app while running another application. Thats what "running in the background means". Else Last.fm would add a scrobbler.

How long did you let it run? I can get an app to keep running for about a minute after it exits, then it gets killed. From various blogs, others have the same experience.

Tom

iphonehere
Aug 7, 2008, 04:48 PM
I tried timer and thread.
They could run about half a minute after I press sleep. Then it goes to "REAL SLEEP".

And I checked the log of the phone when it is running my app, some system logs showed the activities of putting the phone to sleep.

But when I tried with aol radio, I didn't see that sign.

So there should have some tricks to do so.

Garrett
Aug 7, 2008, 05:33 PM
How long did you let it run? I can get an app to keep running for about a minute after it exits, then it gets killed. From various blogs, others have the same experience.

Tom

I only tested for about 45 seconds, after 2 minutes mine dies. :(

iphonehere
Aug 7, 2008, 06:51 PM
I am going to submit technical support request on this.

stay tuned.