Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bignumbers

macrumors regular
Original poster
May 9, 2002
206
0
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

macrumors regular
Original poster
May 9, 2002
206
0
Never mind - found it:

applicationWillResignActive:

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

iphonehere

macrumors newbie
Aug 7, 2008
14
0
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.
 

iphonehere

macrumors newbie
Aug 7, 2008
14
0
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

macrumors regular
Apr 4, 2007
173
0
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

macrumors member
Jul 12, 2008
37
0
Fairfax, VA
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

macrumors member
Jul 12, 2008
37
0
Fairfax, VA
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

macrumors newbie
Aug 7, 2008
14
0
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

macrumors regular
Apr 4, 2007
173
0
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. :(
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.