Audio Session Programming Guide

Audio Guidelines By App Type

The latest driving game does not have the same audio requirements as a real-time video chat app. The following sections provide design guidelines for different types of audio apps.

Audio Guidelines for Game Apps

Most games require user interaction for anything to happen in the game. Use the AVAudioSessionCategoryAmbient or AVAudioSessionCategorySoloAmbient categories when designing games. When users bring up another app or lock the screen, they do not expect the app to continue playing. Often the user wants the audio from another app to continue playing while the game app plays.

Apple recommends the following guidelines:

Play app sound effects while allowing another app’s audio to play.

Play app soundtrack audio when other audio is not playing, otherwise allow the previous audio to play.

Always attempt to reactivate and resume playback after an end interruption event.

Wait for the user to press the play/record button when the app enters the foreground before activating the audio session.

Keep the audio session active throughout the app’s lifetime unless it is interrupted.

Update the UI to indicate that audio has paused when it is interrupted. Do not deactivate the audio session or pause/stop player objects.

Check for the presence of the AVAudioSessionInterruptionOptionKey constant and honor its value after an end interruption. Don’t start playing audio again unless the app was playing prior to the interruption.

Pause the audio session due to a route change caused by an unplug event, but keep the audio session active.

Assume the app’s audio session is inactive when it transitions from a suspended to foreground state. Reactive the audio session when the user presses the play button.

Ask the user for permission to record input using the requestRecordPermission: method. Don’t rely on the iOS to prompt the user.

Audio Guidelines for Metering Apps

Metering apps want the minimal amount of system-supplied signal processing applied to the input and output routes. Set the AVAudioSessionCategoryPlayAndRecord category and the measurement mode to minimize signal processing. Also, apps of this type will not mix with other apps.

Apple recommends the following guidelines:

Always attempt to reactivate and resume playback after an end interruption event.

Set the audio category before displaying a video splash on app launch.

Ask the user for permission to record input using the requestRecordPermission: method. Don’t rely on the iOS to prompt the user.

Audio Guidelines for Browser-like Apps That Sometimes Play Audio

Apps like Facebook and Instagram don’t record audio, only playback audio and video. They use the AVAudioSessionCategoryPlayback category and do not obey the ringer switch. These apps also do not mix with other apps.

Pause the audio session due to a route change caused by an unplug event, but keep the audio session active.

Register for remote control events while video is playing and unregister when the video ends.

Update the UI when the app receives a begin interruption event.

Wait for the user to initiate playback after receiving an end interruption event.

Audio Guidelines for Navigation and Workout Apps

Navigations and workout apps use the AVAudioSessionCategoryPlayback or AVAudioSessionCategoryPlayAndRecord categories. The audio from these apps are typically short prompts and will mix with other apps. As it is assumed that the user wants to hear the audio from these apps even when other apps are playing, these apps will duck audio from other apps.