views:

1348

answers:

2

Is there any way to detect if the iPhone wakes up from sleep while you're app is running? Eg: your app is running, the user locks the screen (or the screen auto locks) and some time later the user unlocks the screen and up pops your app. Is there some way to get an event at that point or detect it somehow?

I've tried searching the Google and this forum, but I can't seem to find anything about it.

+9  A: 

See applicationDidBecomeActive: on UIApplicationDelegate.

Kevin Ballard
This doesn't work if the phone goes to sleep. This is gets called when the user hits the sleep/power button. (2.x)
Rhythmic Fistman
This is called when the phone wakes back up. There's a similarly-named method that's called when the phone goes to sleep.
Kevin Ballard
+4  A: 

Stick these in you AppDelegate.m file:

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

     NSLog(@"Asleep");
}

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

     NSLog(@"Awake");
}

@Kevin - Nothing wrong with your answer - thanks by the way. Just thought I'd save the next person a Google search.

Smendrick