How do I start playing audio when in silent mode & locked in iOS 6?
You need to make couple of changes in plist file.
i.e. 1) Set Required background mode to App plays audio
2) set Application does not run in background to YES.
NSError *setCategoryErr = nil;
NSError *activationErr = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
[[AVAudioSession sharedInstance] setActive:YES error:&activationErr];
Then, you need to write these much code in AppDelege
Now, you can easily run audio while phone screen locks or in background.
Had you previously been doing this in your app:
AudioSessionInitialize (NULL, NULL, NULL, NULL);
AudioSessionSetActive(true);
// Allow playback even if Ring/Silent switch is on mute
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty (kAudioSessionProperty_AudioCategory,
sizeof(sessionCategory),&sessionCategory);
I had a user tell me that the audio wasn't working on an app (well before iOS5!). Turned out their ring/silent switch was set to "silent". So I added this code, and it causes the "silent" setting to be overridden. This is useful if you have a music app, for example, and you want to music to continue playing.
The long seeked solution to this could be a location based justification. Basically use the location background service to justify periodic updates to your app and thus trigger an alarm. This could be justified to apple by including a feature like Weather updates, which requires location services.
I'll look into this a bit into the future. Please if you have the time to look into it now, or if you have insight, dont hesitate to post.
Happy hunting.