I'm trying to stop a timer when the power button is pressed but I can't seem to find the right protocol. I've tried applicationDidBecomeActive/applicationWillResignActive and also the EnterBackground/EnterForeground method but my timer only stops if I switch to another application but not when I put it to sleep by pressing the power button. I'm using ios 4.2 on iphone 4. I've looked into the UIApplicationDelegate Protocol Reference and I can't find anything that would check for power button being pressed.
Code:
- (void)applicationDidEnterBackground:(UIApplication *)application {
if (self.repeatingTimer != nil) {
[self stopRepeatingTimer:self];
}
}
- (void)applicationDidEnterForeground:(UIApplication *)application {
if (self.repeatingTimer != nil) {
[self startRepeatingTimer:self];
}
}