Instance Method

setCategory(_:options:)

Sets the audio session’s category with the specified options.

Declaration

func setCategory(_ category: AVAudioSession.Category, options: AVAudioSession.CategoryOptions = []) throws

Parameters

category

The category to apply to the audio session. See AVAudioSession.Category for supported category values.

options

A mask of additional options for handling audio. For a list of constants, see AVAudioSession.CategoryOptions.

Return Value

true if the audio session category and options were set successfully; otherwise false.

Discussion

The audio session’s category defines how you intend to use audio in your app. Typically, you set the category before activating the session. You can also set the category while the session is active, but doing so results in an immediate route change.

You can tailor the behavior of certain categories by specifying a mask of category options. Specifying an unsupported option for the indicated category results in an error. See AVAudioSession.CategoryOptions for category compatibility.

See Also

Configuring the Audio Session

var category: AVAudioSession.Category

The current audio session category.

func setCategory(AVAudioSession.Category)

Sets the audio session’s category.

var availableCategories: [AVAudioSession.Category]

The audio session categories available on the current device.

struct AVAudioSession.Category

Audio session category identifiers.

var categoryOptions: AVAudioSession.CategoryOptions

The set of options associated with the current audio session category.

struct AVAudioSession.CategoryOptions

Constants that specify optional audio behaviors.

var mode: AVAudioSession.Mode

The current audio session’s mode.

func setMode(AVAudioSession.Mode)

Sets the audio session’s mode.

var availableModes: [AVAudioSession.Mode]

The audio session modes available on the device.

struct AVAudioSession.Mode

Audio session mode identifiers.

enum AVAudioSession.RouteSharingPolicy

Cases that indicate the possible route-sharing policies for an audio session.