User guide

Adding audio session code to handle interruptions ensures that your apps audio continues behaving gracefully
when a phone call arrives, a Clock or Calendar alarm sounds, or another app activates its audio session.
An audio interruption is the deactivation of your app’s audio session—which immediately stops or pauses your
audio, depending on which technology you are using. Interruptions happen when a competing audio session
from an app activates and that session is not categorized by the system to mix with yours. After your session
goes inactive, the system sends a “you were interrupted” message which you can respond to by saving state,
updating the user interface, and so on.
Your app may get suspended following an interruption. This happens when a user decides to accept a phone
call. If a user instead elects to ignore a call, or dismisses an alarm, the system issues an interruption-ended
message, and your app continues running. For your audio to resume, your audio session must be reactivated.
Audio Interruption Handling Techniques
Handle audio interruptions by registering for the appropriate NSNotification. What you do within your
interruption code depends on the audio technology you are using and on what you are using it for—playback,
recording, audio format conversion, reading streamed audio packets, and so on. Generally speaking, you need
to ensure the minimum possible disruption, and the most graceful possible recovery, from the perspective of
the user.
Table 3-1 summarizes appropriate audio session behavior during an interruption. If you use the AVAudioPlayer
or AVAudioRecorder objects, some of these steps are handled automatically by the system.
Table 3-1 What should happen during an audio session interruption
Save state and context
Update user interface
After interruption starts
Restore state and context
Reactivate audio session if app
appropriate
Update user interface
After interruption ends
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
26
Responding to Interruptions