To prevent the application from sleeping when the screen is locked, you must set your audio session to be of type kAudioSessionCategory_MediaPlayback.
Here is an example:
UInt32 category = kAudioSessionCategory_MediaPlayback; OSStatus result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category); if (result){ DebugLog(@"ERROR SETTING AUDIO CATEGORY!\n"); } result = AudioSessionSetActive(true); if (result) { DebugLog(@"ERROR SETTING AUDIO SESSION ACTIVE!\n"); }
If you do not set the audio session category, your application will sleep.
This will cause the application to not sleep as long as you continue to play audio. If you stop playing audio and the screen is still locked, the application will go into sleep mode and your timers will be paused.
If you want the application not to weaken indefinitely, you will need to play a βquietβ audio file so that it does not wake up.
I have an example code here: iPhone Prevention of Sleep
Brian Stormont Nov 20 '09 at 1:53 2009-11-20 01:53
source share