Determining when iPhone has gone to "sleep"?

Discussion in 'iPhone/iPad Programming' started by bignumbers, Jul 15, 2008.

  1. macrumors regular

    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.)

  2. macrumors regular

    Never mind - found it:


    Now I just need to figure out how to use it!
  3. macrumors newbie

    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?

  4. macrumors member

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

  5. macrumors newbie

    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.

  6. macrumors regular

    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 would add a scrobbler.
  7. macrumors member

    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... ;-)

  8. macrumors member

    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.

  9. macrumors newbie

    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.
  10. macrumors regular

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

    I am going to submit technical support request on this.

    stay tuned.

Share This Page