User guide
All of the above behavior is provided by the default audio session category,
AVAudioSessionCategorySoloAmbient. Working with Categories (page 18) provides information on how
to incorporate a category into your app.
Your audio session begins automatically when you start to play or record audio; however, relying on the default
activation is a risky state for your app. For example, if an iPhone rings and the user ignores the call—leaving
your app running—your audio may no longer play, depending on which playback technology you’re using.
The next section describes some strategies for dealing with such issues, and Responding to Interruptions (page
26) goes into depth on the topic.
You can take advantage of default behavior as you’re bringing your app to life during development. However,
the only times you can safely ignore the audio session for a shipping app are these:
●
Your app uses System Sound Services or the UIKit playInputClick method for audio and uses no other
audio APIs.
System Sound Services is the iOS technology for playing user-interface sound effects and for invoking
vibration. It is unsuitable for other purposes. (See System Sound Services Reference and the Audio UI Sounds
(SysSound) sample code project.)
The UIKit playInputClick method lets you play standard keyboard clicks in a custom input or keyboard
accessory view. Its audio session behavior is handled automatically by the system. See Playing Input Clicks
in Text Programming Guide for iOS .
●
Your app uses no audio at all.
In all other cases, do not ship your app with the default audio session.
Why a Default Audio Session Usually Isn’t What You Want
If you don’t initialize, configure, and explicitly use your audio session, your app cannot respond to interruptions
or audio hardware route changes. Moreover, your app has no control over OS decisions about audio mixing
between apps.
Here are some scenarios that demonstrate audio session default behavior and how you can change it:
●
Scenario 1. You write an audio book app. A user begins listening to The Merchant of Venice . As soon as
Lord Bassanio enters, Auto-Lock times out, the screen locks, and your audio goes silent.
To ensure that audio continues upon screen locking, configure your audio session to use a category that
supports playback and set the audio flag in UIBackgroundModes.
Defining an Audio Session
Why a Default Audio Session Usually Isn’t What You Want
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
11