views:

49

answers:

1

Is there any notification I can listen to that will alert me that the phone will go to sleep? I have implemented the following:

[[NSNotificationCenter defaultCenter] 
              addObserver:self 
                 selector:@selector(resignActive:)
                     name:UIApplicationDidEnterBackgroundNotification
                   object:nil];

but it seems that it's not getting triggered when the phone goes to sleep after some time of inactivity (1 min in my settings). The reason I think it's not working is that I have a timer that perform an action every second and if a certain time has passed (bigger than one minute) it issues an audio alarm. In my resignActive I invalidate my timer and that works fine when I press the home button, but not when the phone goes to sleep. It still seems to be running in the background but "at a lower speed" as the times are much longer than normal (around 10 min instead of 2 min).

Any ideas what's happening when the phone goes to sleep? I have read these two posts but it doesn't really answer my question.

http://stackoverflow.com/questions/411436/what-happens-to-an-iphone-app-when-iphone-goes-into-stand-by-mode

http://stackoverflow.com/questions/2396786/iphone-app-is-delayed-for-10-15-minutes-when-iphone-is-in-sleep-mode

A: 

Implements those 2 methods on the UIApplicationDelegate :

- (void)applicationWillResignActive:(UIApplication *)application
- (void)applicationDidBecomeActive:(UIApplication *)application

It will be called also when a push notification from another app (or a SMS) is shown...

TheSquad
What a good start of the week.Based on your concise and correct answer I changed my method above to subscribe to UIApplicationWillResignActive.It now works as I want it to.Thanks for a perfect answer. Wish they were all like this.
Structurer
just happy to help... have a nice week
TheSquad