Play Audio While the Silent Switch is ON

I’d receive emails from time to time complaining my apps that have no sound. However, its actually caused by the user turing on the Silent Switch…

To enable audio playing even when the user turned on the silent switch. Simply put the following code in your app delegate while its launching.

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil];
[audioSession setActive:YES error:nil];

The AVAudioSessionCategoryPlayback category enable your app to play audio while silent switch is on (and even the screen is locked). AVAudioSessionCategoryOptionMixWithOthers allow your audio to mix with other audio from other apps, and of course, its optional.

Play Audio While the Silent Switch is ON

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s