Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jul 15, 2008, 04:52 PM   #1
bignumbers
macrumors regular
 
Join Date: May 2002
Determining when iPhone has gone to "sleep"?

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 is offline   0 Reply With Quote
Old Jul 15, 2008, 05:14 PM   #2
bignumbers
Thread Starter
macrumors regular
 
Join Date: May 2002
Never mind - found it:

applicationWillResignActive:

Now I just need to figure out how to use it!
bignumbers is offline   0 Reply With Quote
Old Aug 7, 2008, 02:35 PM   #3
iphonehere
macrumors newbie
 
Join Date: Aug 2008
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 is offline   0 Reply With Quote
Old Aug 7, 2008, 02:44 PM   #4
SwampThingTom
macrumors member
 
Join Date: Jul 2008
Location: Fairfax, VA
Quote:
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
SwampThingTom is offline   0 Reply With Quote
Old Aug 7, 2008, 02:48 PM   #5
iphonehere
macrumors newbie
 
Join Date: Aug 2008
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.


Quote:
Originally Posted by SwampThingTom View Post
You can't. Apple doesn't allow apps to run in the background.

Tom
iphonehere is offline   0 Reply With Quote
Old Aug 7, 2008, 03:38 PM   #6
Garrett
macrumors regular
 
Join Date: Apr 2007
Quote:
Originally Posted by SwampThingTom View Post
You can't. Apple doesn't allow apps to run in the background.

Tom
You sure speak like thats the answer.

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.
__________________
MacBook - White - 2.0GHz Intel Core 2 Duo - 2GB memory - 80GB hard drive
iPhone 16 GB 3G
Garrett is offline   0 Reply With Quote
Old Aug 7, 2008, 03:57 PM   #7
SwampThingTom
macrumors member
 
Join Date: Jul 2008
Location: 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 is offline   0 Reply With Quote
Old Aug 7, 2008, 03:59 PM   #8
SwampThingTom
macrumors member
 
Join Date: Jul 2008
Location: Fairfax, VA
Quote:
Originally Posted by Garrett View Post
You sure speak like thats the answer.

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
SwampThingTom is offline   0 Reply With Quote
Old Aug 7, 2008, 04:48 PM   #9
iphonehere
macrumors newbie
 
Join Date: Aug 2008
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.
iphonehere is offline   0 Reply With Quote
Old Aug 7, 2008, 05:33 PM   #10
Garrett
macrumors regular
 
Join Date: Apr 2007
Quote:
Originally Posted by SwampThingTom View Post
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.
__________________
MacBook - White - 2.0GHz Intel Core 2 Duo - 2GB memory - 80GB hard drive
iPhone 16 GB 3G
Garrett is offline   0 Reply With Quote
Old Aug 7, 2008, 06:51 PM   #11
iphonehere
macrumors newbie
 
Join Date: Aug 2008
I am going to submit technical support request on this.

stay tuned.
iphonehere is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Resolved: 13" MacBook Pro Retina not display "switch user" after sleep mtbdudex MacBook Pro 1 Mar 1, 2014 01:46 PM
external firewire 800 disk enclosure "sleep with mavericks" ssls6 OS X Mavericks (10.9) 6 Feb 20, 2014 06:22 AM
iTunes "determining gapless playback" on MP3s Traverse OS X Mavericks (10.9) 3 Dec 14, 2013 07:44 PM
HELP: Why does it take 4 to 5 times of clicking "Sleep" for it to finally sleep?! magentawave MacBook Pro 2 Jan 21, 2013 03:11 PM
Start a new tab similar to "iOS blog" and "Mac blog" but make it "IPhone Leaks?" Dewroo Site and Forum Feedback 2 Aug 23, 2012 09:47 AM

Forum Jump

All times are GMT -5. The time now is 12:34 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC