Determining when iPhone has gone to "sleep"?

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

  1. macrumors regular

    Joined:
    May 9, 2002
    #1
    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!
     
  2. thread starter macrumors regular

    Joined:
    May 9, 2002
    #2
    Never mind - found it:

    applicationWillResignActive:

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

    Joined:
    Aug 7, 2008
    #3
    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.
     
  4. macrumors member

    Joined:
    Jul 12, 2008
    Location:
    Fairfax, VA
    #4
    You can't. Apple doesn't allow apps to run in the background.

    Tom
     
  5. macrumors newbie

    Joined:
    Aug 7, 2008
    #5
    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

    Joined:
    Apr 4, 2007
    #6
    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.
     
  7. macrumors member

    Joined:
    Jul 12, 2008
    Location:
    Fairfax, VA
    #7
    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
     
  8. macrumors member

    Joined:
    Jul 12, 2008
    Location:
    Fairfax, VA
    #8
    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
     
  9. macrumors newbie

    Joined:
    Aug 7, 2008
    #9
    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

    Joined:
    Apr 4, 2007
    #10
    I only tested for about 45 seconds, after 2 minutes mine dies. :(
     
  11. macrumors newbie

    Joined:
    Aug 7, 2008
    #11
    I am going to submit technical support request on this.

    stay tuned.
     

Share This Page