Audio Session — what it is, categories and configuration in iOS

Author: IT Sectr Published: 2026-05-24 Reading time: 8 min

Audio Session is the central iOS mechanism for managing an app’s audio behavior: interaction with the system, handling interruptions, and audio routing. Every iOS app receives a single audio session that determines how sound behaves when the screen is locked, during calls, and when connecting Bluetooth. According to Apple Developer Documentation, 2026, Audio Session is configured through a category and mode — without proper configuration, the app may not play sound in the background.

Key Takeaways

  • Audio Session (AVAudioSession) is a system object in iOS that manages an app’s audio behavior at the OS level.
  • The session category defines the basic behavior: playback, record, ambient, playAndRecord, and others.
  • Modes and options refine the behavior: default, voiceChat, videoRecording, allowBluetooth.
  • On interruption (call, alarm) the session receives a notification through NotificationCenter with the interruptionType.
  • For background playback, you need to enable Background Modes — Audio, AirPlay and Picture in Picture.

What is Audio Session?

Audio Session is a single AVAudioSession instance created by the system when an app launches and exists throughout its entire lifecycle. It acts as an intermediary between the app and the iOS audio system: the category configuration determines whether the app is allowed to play sound in the background, whether sound will be muted during a call, and which devices to output audio to.

Unlike Android Audio Focus, where each app independently requests and releases focus, iOS Audio Session is centrally managed through one session per app. When a session is activated, the system automatically deactivates the previous app’s session, sending it an interruption notification. This architectural difference defines the different approaches to audio handling on the two platforms.

According to WWDC 2024 Session 211, about 40% of audio problems in iOS apps are caused by incorrect Audio Session configuration. The most common mistake is choosing the ambient category instead of playback, which causes sound to disappear when the screen is locked.

How AVAudioSession Works

When launched, an app gets the sharedInstance of the session, sets the category via the setCategory(_:mode:options:) call, and activates the session through setActive(true). After activation, iOS considers the category policies for routing. If another app activates its session, the current one receives an AudioSessionInterruptionType.began notification through Notification.Name.AVAudioSessionInterruption.

Audio Session Categories

The category is the main parameter of Audio Session, defining six predefined behavior options. Choosing a category is the first and most important decision when setting up audio in iOS.

CategoryWhen to UseBackground AudioMute Switch Affects
ambientGames, background effectsNoYes
playbackMusic, podcasts, audiobooksYesNo
recordVoice memos, audio recordingNoN/A
playAndRecordVoIP, voice messagesYesNo
multiRouteDJ mixers, karaokeYesNo
soloAmbientDefault (iOS default)NoYes

Playback Category — the Main Choice for Players

For music and video players, always use playback. This category allows: playing sound with the screen locked, with the mute switch turned off (physical button on the iPhone case), and when the app is in the background. Without the playback category, the session is deactivated when the screen locks or the app is minimized.

The ambient category is suitable for games and apps with background sounds — it allows other apps to continue playing. For example, if a user is listening to music and opens a game with an ambient session, the music continues to play over the game sounds. This is a fundamental difference from Android, where such a scenario requires explicit duck permission.

How to Set Up Audio Session

Audio Session configuration should be done before any playback begins. It is recommended to configure the session in the application(_:didFinishLaunchingWithOptions:) method or in the player’s initializer. After setting the category, the session must be activated.

Basic Audio Session Setup in Swift

swift
import AVFAudio

let session = AVAudioSession.sharedInstance

do {
    try session.setCategory(
        playback,
        mode: default,
        options: [allowBluetooth, defaultToSpeaker]
    )
    try session.setActive(true)
} catch {
    print("Audio Session setup failed: \(error.localizedDescription)")
}

The options parameter includes allowBluetooth (output to Bluetooth headset) and defaultToSpeaker (playback through the speaker rather than the earpiece). The allowBluetooth option is required for apps that support Bluetooth headphones — without it, sound may be routed to the built-in speaker even when a headset is connected.

Configuration for Recording and Playback (VoIP)

swift
let session = AVAudioSession.sharedInstance
try session.setCategory(
    playAndRecord,
    mode: voiceChat,
    options: [allowBluetooth, allowBluetoothA2DP]
)

try session.overrideOutputAudioPort(speaker)
try session.setActive(true)

The playAndRecord category with voiceChat mode optimizes the audio path for voice communication: enables echo cancellation, automatic gain control (AGC), and selects the optimal codec. OverrideOutputAudioPort(.speaker) forces output through the speaker even when a headset is connected — useful for speakerphone.

Session Activation and Deactivation

Calling setActive(true) activates the session and notifies the system that the app will use audio. When playback is paused, it is recommended to deactivate the session so that other apps can get the audio stream. The exception is apps with long-term background playback (music, podcasts), where the session remains active throughout the entire track.

It is important to handle errors when calling setActive. If another session with high priority is active (for example, Phone during a call), setActive may throw an error. In this case, you need to wait for the AudioSessionInterruptionType.ended notification and retry activation.

Audio Session Modes and Policies

Mode refines the category and optimizes the audio path for a specific use case. Each mode changes the behavior of AGC, echo cancellation, and codecs. Modes do not replace the category but complement it — one category can work with different modes.

  • default — standard mode for music and video. AGC is off, echo cancellation is minimal.
  • voiceChat — optimization for VoIP. Enables echo cancellation, AGC, noise suppression. Use with the playAndRecord category.
  • videoRecording — for video recording. Prioritizes recording quality over playback. Use with the record or playAndRecord category.
  • measurement — for audio measurements. Minimal signal processing, no AGC or echo cancellation.
  • gameChat — for voice chat in games. Similar to voiceChat, but with priority for game audio.
  • moviePlayback — for watching movies. Optimization for multichannel audio (5.1, 7.1) and Dolby Atmos.

Audio Session Category Options

Options provide fine-tuning of session behavior. Each option is a flag that can be combined with others in an array. For example, [.allowBluetooth, .defaultToSpeaker, .interruptSpokenAudioAndMix] allows sound output to a Bluetooth headset, uses the speaker by default, and mixes with audiobooks.

On iOS 17+, the spatialAudio option appeared, which enables personalized spatial audio for AirPods via AVAudioSessionSpatialPreferences. According to WWDC 2024, spatial audio increases user engagement in music apps by 25% in Apple’s tests.

Handling Interruptions and Calls

Interruptions are a key difference between Audio Session and Android Audio Focus. In iOS, interruptions are handled through NotificationCenter by subscribing to AVAudioSession.interruptionNotification. The notification contains a dictionary with the interruption type: began or ended.

Subscribing to Interruption Notifications

swift
override func viewDidLoad() {
    super.viewDidLoad()
    let center = NotificationCenter.default
    center.addObserver(
        self,
        selector: #selector(handleInterruption),
        name: AVAudioSession.interruptionNotification,
        object: nil
    )
}

@objc func handleInterruption(_ notification: Notification) {
    guard let userInfo = notification.userInfo,
        let type = userInfo[AVAudioSession.interruptionTypeKey]
            as? AVAudioSessionInterruptionType
    else { return }

    switch type {
    case began:
        pausePlayback()
    case ended:
        guard let options = userInfo[AVAudioSession.interruptionOptionKey]
            as? AVAudioSessionInterruptionOptions
        else { return }

        if options.contains(shouldResume) {
            resumePlayback()
        }
    }

When interruptionType.began is received, the player should pause playback. When interruptionType.ended is received, the interruptionOptionKey property indicates whether the player can automatically resume (shouldResume). If the user declined the call, shouldResume = true. If the call ended by timeout — shouldResume = false, resumption is not allowed.

Handling Interruptions from Other Apps

When another app activates its Audio Session with the playback category, the current session receives an interruption notification. If another app uses ambient, no interruption occurs — sounds are mixed. This behavior is drastically different from Android, where any Audio Focus activation triggers a LOSS event.

For apps that need to continue playback when other sessions are activated (for example, navigation while music is playing), use the .mixWithOthers option. This option allows sound mixing with other apps, and no interruptions are sent. MixWithOthers is the iOS equivalent of the duck mode in Android.

Audio Routing and Bluetooth

Audio Session automatically manages audio routing between built-in speakers, headphones, Bluetooth headsets, and AirPlay devices. The app can monitor the current route through the currentRoute property and receive notifications about changes via AVAudioSession.routeChangeNotification.

When Bluetooth headphones are connected, iOS automatically switches the audio output to them if the session is configured with the allowBluetooth option. Without this option, sound continues through the built-in speaker. Starting with iOS 16, when AirPods Pro are connected, the system automatically enables ProMotion synchronization to reduce latency.

Monitoring Route Changes

Subscribing to routeChangeNotification allows reacting to headphone connection and disconnection. When a Bluetooth headset is disconnected, the player should pause playback — the user might not expect sound to start playing from the phone’s speaker. According to Apple HIG (2026), this is required behavior for music apps.

The availableInputs and availableOutputs properties return a list of available audio devices with their types (builtInSpeaker, headphones, bluetoothA2DP, hdmi). The developer can programmatically select a specific device through overrideOutputAudioPort for custom routing scenarios.

Frequently Asked Questions

How is Audio Session different from Android Audio Focus?

The key difference is architecture. Audio Session is a single centralized session per app that is configured once. Audio Focus in Android requires manually requesting focus each time when playing. Additionally, iOS supports mixing through the mixWithOthers option, while in Android duck is the only alternative to complete stop.

Why does sound disappear when the iPhone screen is locked?

The most common cause is an incorrect Audio Session category. If ambient or soloAmbient is selected, sound stops when the screen is locked. Switch the category to playback and make sure that Background Modes — Audio, AirPlay, and Picture in Picture is added to Info.plist.

How to allow two apps to play simultaneously on iOS?

Add the .mixWithOthers option to setCategory. This will allow mixing your app’s sound with other active sessions. Without this option, a new app interrupts the current one. MixWithOthers is the analog of duck mode in Android, but with full volume preservation.

How to programmatically switch sound to a Bluetooth speaker?

Use overrideOutputAudioPort with nil for automatic selection. For forced output to Bluetooth: get the AVAudioSessionRouteDescription from availableOutputs, select a port with the .bluetoothA2DP type and pass it to overrideOutputAudioPort. Make sure the session is configured with allowBluetooth.

Should I call setActive(false) when pausing the player?

For most apps — yes. Deactivating the session on pause allows other apps to get audio focus. The exception is music players with long-term background playback. If the pause is short (less than 5 seconds), it’s better to keep the session active for quick resumption.

Summary

  • Audio Session (AVAudioSession) is the single audio session per app in iOS that manages sound behavior at the OS level.
  • Six categories: ambient, playback, record, playAndRecord, multiRoute, soloAmbient — define the basic audio behavior.
  • For background playback, the playback category and Background Modes in Info.plist are required.
  • Interruptions are handled through NotificationCenter with began (pause) and ended (resume when shouldResume) types.
  • The .mixWithOthers option enables sound mixing with other apps without interruption.
  • Routing is managed automatically but monitored through routeChangeNotification for pausing when headphones are disconnected.
  • The playAndRecord category with voiceChat mode is the standard for VoIP apps with echo cancellation and AGC.

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project

Read also