User guide
●
Is audio that you play essential or peripheral to using your app? If essential, the best category is one that
supports continued playback when the Ring/Silent switch is set to silent. If peripheral, pick a category that
goes silent with the Ring/Silent switch set to silent.
●
Is other audio (such as the Music app) playing when the user launches your app? Checking during launch
enables you to branch. For example, a game app could choose a category configuration that allows music
to continue if it’s already playing, or choose a different category configuration to support a built-in app
soundtrack otherwise.
The following list describes the categories and the audio behavior associated with them. The
AVAudioSessionCategoryAmbient category allows other audio to continue playing; that is, it is a mixable
app. The remaining categories indicate that you want other audio to stop when your session becomes active.
However, you can customize the non-mixing “playback” and “play and record” categories to allow mixing, as
described in Fine-Tuning a Category (page 24).
●
AVAudioSessionCategoryAmbient—Playback only. Plays sounds that add polish or interest but are
not essential to the app’s use. Using this category, your audio is silenced by the Ring/Silent switch and
when the screen locks.
●
AVAudioSessionCategorySoloAmbient—(Default) Playback only. Silences audio when the user
switches the Ring/Silent switch to the “silent” position and when the screen locks. This category differs
from the AVAudioSessionCategoryAmbient category only in that it interrupts other audio.
●
AVAudioSessionCategoryPlayback—Playback only. Plays audio even with the screen locked and with
the Ring/Silent switch set to silent. Use this category for an app whose audio playback is of primary
importance.
Note: If you choose an audio session category that allows audio to keep playing when the
screen locks, you must set the UIBackgroundModes audio in your app’s info.plist. See
UIBackgroundModes for more information. You should normally not disable the system’s sleep
timer via the idleTimerDisabled property. If you do disable the sleep timer, be sure to reset
this property to NO when your app does not need to prevent screen locking. The sleep timer
ensures that the screen goes dark after a user-specified interval, saving battery power.
●
AVAudioSessionCategoryRecord—Record only. Use AVAudioSessionCategoryPlayAndRecord
if your app also plays audio.
●
AVAudioSessionCategoryPlayAndRecord—Playback and record. The input and output need not
occur simultaneously, but can if needed. Use for audio chat apps.
●
AVAudioSessionCategoryAudioProcessing—Offline audio processing only. Performs offline audio
processing and no playing or recording.
Working with Categories
Choosing the Best Category
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
19