One more feature that Apple has provided to iDevelopers that is very useful. If you are building something like audio player iphone application and if you want player to play even if iPhone is locked then you must use this code below:
UInt32 category = kAudioSessionCategory_MediaPlayback; //1
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (category), &category); //2
AudioSessionSetActive (true); //3
Code explanation :
1. Set the audio session category – kAudioSessionCategory_MediaPlayback.
2. Will ensure our audio playback contiues when the device is locked.
3. Activate the audio session immmediately before playback starts.
Just put this code in play method definition in implementation of your player class.
And that is all.



I am sorry – but where exactly do you place this? Can’t figure it out. Thanks.
Hello Sean,
You can put it where ever you want in code implementation. For example in constructor of some class (-(id)init…), in method where you create instance of AVAudioPlayer or in method where you trigger play method of same instance.
Cheers,
Ivan