> For a complete documentation index, fetch https://docs.voximplant.ai/llms.txt

# VIAudioManager

Interface that provides API to manage audio devices on iOS.

@objc final class VIAudioManager

Limitations:

* It is not possible to select an [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7) while a wired headset is connected.
* It is not possible to select an [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7) while a Bluetooth A2DP device is connected.
* Wired headsets without a microphone may be recognized and selected as [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7).
* iOS 12 and AirPods: during an active call or conference, [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7) or [VIAudioDevice.VIDeviceType.speaker](/api-reference/iossdk/core/viaudiodevice#symbol-05bf8a66181bc378) selection may fail if AirPods are used as the current active device.
* If a [VIAudioDevice.VIDeviceType.unsupported](/api-reference/iossdk/core/viaudiodevice#symbol-348d6596bc1b7817) device is connected during an active call or conference, the audio path may be interrupted for a few seconds.
* It is not possible to select an [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7) while a call is on hold and reported to [CallKit](https://developer.apple.com/documentation/callkit).

## Properties

### currentDevice

@objc var currentDevice: [VIAudioDevice](/api-reference/iossdk/core/viaudiodevice)? \{ get }

Active audio device during a call or conference. If none is in progress, the device selected for the next one.

Connecting a new device can change the active device. When a new device connects, the SDK triggers [audioManager(\_:didAddDevice:)](/api-reference/iossdk/core/viaudiomanagerdelegate#symbol-b08833dff4e35b31).

### delegate

@objc weak var delegate: [VIAudioManagerDelegate](/api-reference/iossdk/core/viaudiomanagerdelegate)?

Delegate that receives audio device list and audio session error events.

### deviceList

@objc lazy var deviceList: \[[VIAudioDevice](/api-reference/iossdk/core/viaudiodevice)] \{ get set }

Available audio devices.

Consider the following known issues and limitations for Bluetooth devices. They apply to calls and conferences:

* Before a call or conference: if AirPods are connected but not worn, AirPods appear in the list when the call or conference starts and they are worn.
* Before a call or conference: some Bluetooth devices are not detected until the call or conference starts.
* During a call or conference: if a Bluetooth device is placed in its case after another device is selected by [setActiveDevice(\_:completion:)](/api-reference/iossdk/core/viaudiomanager#symbol-f45ae3cc214fbb8d), the list is not updated until the next device selection.
* During a call or conference: if the active device is switched from Bluetooth to another device by [setActiveDevice(\_:completion:)](/api-reference/iossdk/core/viaudiomanager#symbol-f45ae3cc214fbb8d), the Bluetooth device remains in the list after Bluetooth is turned off on the phone until the next device selection.

USB audio devices are [VIAudioDevice.VIDeviceType.unsupported](/api-reference/iossdk/core/viaudiodevice#symbol-348d6596bc1b7817). They are not added to the list. [audioManager(\_:didReceiveError:)](/api-reference/iossdk/core/viaudiomanagerdelegate#symbol-b3f627400d6d8dbc) is triggered when the current audio route includes a USB output.

### shared

@objc static let shared: [VIAudioManager](/api-reference/iossdk/core/viaudiomanager)

Shared audio manager instance.

## Methods

### callKitProviderDidActivateAudioSession()

@objc func callKitProviderDidActivateAudioSession()

Notifies the SDK that the CallKit framework has activated the audio session.

This is the counterpart to [callKitProviderDidDeactivateAudioSession()](/api-reference/iossdk/core/viaudiomanager#symbol-e1d552fc41e81751). Both methods should be called for proper CallKit integration.

> **Warning**
>
> * Call this method inside [provider(\_:didActivate:)](https://developer.apple.com/documentation/callkit/cxproviderdelegate/provider\(_:didactivate:\)).
> * Use this method alongside `VICallSettings.callKitSupport` set to `true`.

### callKitProviderDidDeactivateAudioSession()

@objc func callKitProviderDidDeactivateAudioSession()

Notifies the SDK that the CallKit framework has deactivated the audio session.

This is the counterpart to [callKitProviderDidActivateAudioSession()](/api-reference/iossdk/core/viaudiomanager#symbol-c1e4be749dd7ec78). Both methods should be called for proper CallKit integration.

> **Warning**
>
> * Call this method inside [provider(\_:didDeactivate:)](https://developer.apple.com/documentation/callkit/cxproviderdelegate/provider\(_:diddeactivate:\)).
> * Use this method alongside `VICallSettings.callKitSupport` set to `true`.

### setActiveDevice(\_:completion:)

@objc func setActiveDevice(\
    \_ device: [VIAudioDevice](/api-reference/iossdk/core/viaudiodevice),\
    completion: @escaping ([VIAudioDeviceError](/api-reference/iossdk/core/viaudiodeviceerror)?) -> Void\
)

Sets the specified audio device as active.

**Parameters**

**device** [VIAudioDevice](/api-reference/iossdk/core/viaudiodevice)

Preferred audio device to use

**completion** @escaping ([VIAudioDeviceError](/api-reference/iossdk/core/viaudiodeviceerror)?) -> Void

Completion handler invoked when the operation finishes. This handler is executed on the SDK delegate queue. Passes a [VIAudioDeviceError](/api-reference/iossdk/core/viaudiodeviceerror) if the operation has failed; `nil` if it has succeeded.

There are two cases:

* Before a call or conference. The method does not activate an audio device, it just selects (i.e. points to) the audio device to be activated.
* During a call or conference. If the selected audio device is available, the method activates this audio device.

The active device may change when a new device is connected. [audioManager(\_:didAddDevice:)](/api-reference/iossdk/core/viaudiomanagerdelegate#symbol-b08833dff4e35b31) is triggered for the connected device.

If the application uses [CallKit](https://developer.apple.com/documentation/callkit), you should take into consideration:

* If a Bluetooth headset is connected, audio routing depends on where a call is answered (from a Bluetooth headset or the phone screen). A Bluetooth headset is activated only if a call is answered via the Bluetooth headset controls. Otherwise audio is played via [VIAudioDevice.VIDeviceType.receiver](/api-reference/iossdk/core/viaudiodevice#symbol-06e9e246e31ed6e7).
* Audio is always routed to a Bluetooth headset only if a user selects “Bluetooth headset” as Call Audio Routing in the phone preferences.

## Relationships

**Inherits From:** NSObject

**Conforms To:** ObjectiveC.NSObjectProtocol, Swift.CVarArg, Swift.CustomDebugStringConvertible, Swift.CustomStringConvertible, Swift.Equatable, Swift.Hashable