User guide
if (!success) { /* handle the error in activationError */ }
To deactivate your audio session, pass NO to the setActive parameter.
In the specific case of playing or recording audio with an AVAudioPlayer or AVAudioRecorder object, the
system takes care of audio session reactivation upon interruption end. Nonetheless, Apple recommends that
you register for notification messages and explicitly reactivate your audio session. Thus you can ensure that
reactivation succeeded, and you can update your app’s state and user interface. For more on this, see Figure
3-1 (page 28).
Most apps never need to deactivate their audio session explicitly. Important exceptions include VoIP (Voice
over Internet Protocol) apps, turn-by-turn navigation apps, and, in some cases, recording apps.
●
Ensure that the audio session for a VoIP app, which usually runs in the background, is active only while
the app is handling a call. In the background, standing ready to receive a call, a VoIP app’s audio session
should not be active.
●
Ensure that the audio session for an app using a recording category is active only while recording. Before
recording starts and when recording stops, ensure your session is inactive to allow other sounds, such as
incoming message alerts, to play.
Checking Whether Other Audio Is Playing During App Launch
When a user launches your app, sound may already be playing on the device. For example, the Music app may
be playing music, or Safari may be streaming audio when your app launches. This situation is especially salient
if your app is a game. Many games have a music sound track as well as sound effects. In this case, Sound in
iOS Human Interface Guidelines advises you to assume that users expect the other audio to continue as they
play your game while still playing the game’s sound effects.
Inspect the otherAudioPlaying property to determine if audio is already playing when you launch your
app. If other audio is playing when your app launches, mute your game’s soundtrack and assign the
AVAudioSessionCategorySoloAmbient category. See Working with Categories (page 18) for more
information on categories.
Defining an Audio Session
Checking Whether Other Audio Is Playing During App Launch
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
16