views:

562

answers:

1

Hello,

Is there a way to determine if the screen has been shut off via the top Power button?

I just need to know if the screen has been somehow set to off to kill a loop that updates location.

Thanks

+17  A: 

Your Application delegate will receive a applicationWillResignActive: message just before the screen is locked (or when the phone rings or another window pops up). This is an excellent time to kill any idle-time processes. After re-activating, you'll receive an applicationDidBecomeActive: message, in which you can restart all this stuff.

Ben Gottlieb
Note that you can subscribe to this message from within any class, you do not necessarily have to use the application delegate to receive the notification.
Kendall Helmstetter Gelner
Ben clearly answered your explicit question regarding "screen shutoff notifications." However, I think your question is a bit mis-guided since you mention that you just want to "kill a loop" when the screen is turned off. Your entire program (including the loop) will stop when about 20 seconds after the screen is turned off. It will then resume once the screen is turned back on. Just a helpful note for others who might assume they need to manually kill loops when the screen is shut off...
Clint Harris