Preventing sleep
From IPhone Dev FAQ
Actually, you cannot.
There are two distinct "sleep" modes that the iPhone has: locking (turning off) the screen, and actual sleep. The device goes to sleep only while the screen is locked, and this you cannot prevent. But you can prevent the device from locking the screen automatically by disabling the idle timer (for example, if you're using the accelerometer for input or your app is designed not to take any input at all).
To do so:
[UIApplication sharedApplication].idleTimerDisabled = YES;
Note that if your app is designed to be used "in the pocket" (ie: a music player), if the user locks the screen, the device will, sooner or later, go to sleep and stop your app and you cannot prevent this. Sorry. In the specific case of music players, you can set up your AudioSession with an appropriate session type to signal the system what you are doing, but this does not guarantee the system won't sleep, so caveat emptor.
