An object that communicates to the system how you intend to use audio in your app.
- iOS 3.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
An audio session acts as an intermediary between your app and the operating system—and, in turn, the underlying audio hardware. You use an audio session to communicate to the operating system the general nature of your app’s audio without detailing the specific behavior or required interactions with the audio hardware. You delegate the management of those details to the audio session, which ensures that the operating system can best manage the user’s audio experience.
All iOS, tvOS, and watchOS apps have a default audio session that comes preconfigured with the following behavior:
It supports audio playback, but disallows audio recording (tvOS doesn’t support audio recording).
In iOS, setting the Ring/Silent switch to silent mode silences any audio the app is playing.
In iOS, locking a device silences the app’s audio.
When the app plays audio, it silences any other background audio.
Although the default audio session provides useful behavior, it generally doesn’t provide the audio behavior a media app needs. To change the default behavior, you configure your app’s audio session category.
There are seven possible categories you can use (see Audio Session Categories and Modes), but
playback is the one that playback apps most commonly use. This category indicates that audio playback is a central feature of your app. When you specify this category, your app’s audio continues with the Ring/Silent switch set to silent mode (iOS only). Using this category, you can also play background audio if you’re using the Audio, AirPlay, and Picture in Picture background mode. For more information, see Enabling Background Audio.
You use an
AVAudio object to configure your app’s audio session. This class is a singleton object used to set the audio session’s category, mode, and other configurations. You can interact with the audio session throughout your app’s life cycle, but it’s often useful to perform this configuration at app launch, as shown in the following example.