Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Awake from sleep event on the iPhone?

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.

like image 377
rustyshelf Avatar asked Dec 15 '08 10:12

rustyshelf


2 Answers

See applicationDidBecomeActive: on UIApplicationDelegate.

like image 143
Lily Ballard Avatar answered Sep 20 '22 05:09

Lily Ballard


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.

like image 42
noodl_es Avatar answered Sep 18 '22 05:09

noodl_es