User guide
To set the audio session category, call the setCategory:error: method as shown in Listing 2-1. For
descriptions of all the categories, refer to Choosing the Best Category (page 18).
Listing 2-1 Setting the audio session category using the AV Foundation framework
NSError *setCategoryError = nil;
BOOL success = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryAmbient
error: &setCategoryError];
if (!success) { /* handle the error in setCategoryError */ }
Using Modes to Specialize the Category
While categories set the base behaviors for your app, modes are used to specialize an audio session category.
Set the mode for a category to further define the audio behaviors of your app. There are seven modes to choose
from:
●
AVAudioSessionModeDefault—Default mode that works with all categories and configures the device
for general usage.
●
AVAudioSessionModeVoiceChat—For Voice over IP (VoIP) apps. This mode can be used only with the
AVAudioSessionCategoryPlayAndRecord category. Signals are optimized for voice through
system-supplied signal processing, and the mode sets
AVAudioSessionCategoryOptionAllowBluetooth.
The set of allowable audio routes are optimized for voice chat experience. When the built-in microphones
are used, the system automatically chooses the best combination of built-in microphones for the voice
chat.
●
AVAudioSessionModeVideoChat—For video chat apps such as FaceTime. The video chat mode can
only be used with the AVAudioSessionCategoryPlayAndRecord category. Signals are optimized for
voice through system-supplied signal processing and sets
AVAudioSessionCategoryOptionAllowBluetooth and
AVAudioSessionCategoryOptionDefaultToSpeaker.
The set of allowable audio routes are optimized for video chat experience. When the built-in microphones
are used, the system automatically chooses the best combination of built-in microphones for the video
chat.
Working with Categories
Using Modes to Specialize the Category
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
22