# OTAudioSessionManager Protocol Reference

Conforms to | NSObject
Declared in | OTAudioKit.h

## Overview

Defines an audio session manager for use with calling services like CallKit. Implementation of this protocol is optional. Custom audio devices can implement these methods to manage the AVAudioSession. The default audio device in the SDK provides a working implementation.

For more information, see this documentation.

### `– enableCallingServicesMode` required method

Enables manual activation for the AVAudioSession.

`- (void)enableCallingServicesMode`

#### Discussion

This method prepares the SDK for integration with calling services like CallKit, enabling proper audio routing and session management.

The SDK manages the AVAudioSession configuration, while the application or CallKit is responsible for activating the session.

Note: Call this early in the app lifecycle, typically at launch or before starting any calls.

#### Declared In

`OTAudioKit.h`

### `– preconfigureAudioSessionForCallWithMode:` required method

Configures the audio session with the appropriate settings for a CallKit-based call.

`- (void)preconfigureAudioSessionForCallWithMode:(AVAudioSessionMode _Nullable)mode`

#### Parameters

`mode` | The AVAudioSessionMode to apply during configuration. In general, `AVAudioSessionModeVoiceChat` should be used for VoIP calls to optimize audio performance. If a custom mode is provided for use by a non-default audio device, that mode will be used; otherwise, `AVAudioSessionModeVoiceChat` will be used as the default.

#### Discussion

This method sets up the `AVAudioSession` with settings optimized for the specified mode, including audio category, mode, and routing configuration. However, it does not activate the session. The session is configured in advance so it can be activated correctly when triggered by a CallKit action.

Note: This method should be called prior to activating the session, typically in response to CallKit’s `CXAnswerCallAction` or `CXStartCallAction`. This ensures proper configuration for later activation by the system. See Apple Developer Forum for more details.

#### Declared In

`OTAudioKit.h`

### `– audioSessionDidActivate:` required method

Notifies the SDK that the audio session has been activated.

`- (void)audioSessionDidActivate:(AVAudioSession *_Nonnull)session`

#### Parameters

`session` | The active `AVAudioSession` instance that was activated by the system.

#### Discussion

This method should be called when the system (for example, via CallKit) has activated the audio session. It informs the SDK that audio is now ready to be used and that the session is active.

Note: This method is only relevant when using `OTAudioSessionManagerModeCallingServices`. If called in other modes, such as `OTAudioSessionManagerModeVideoChat`, it will be ignored since the SDK handles audio session activation automatically.

#### Declared In

`OTAudioKit.h`

### `– audioSessionDidDeactivate:` required method

Notifies the SDK that the audio session has been deactivated.

`- (void)audioSessionDidDeactivate:(AVAudioSession *_Nonnull)session`

#### Parameters

`session` | The `AVAudioSession` instance that has been deactivated.

#### Discussion

This method should be called when the system (for example, CallKit) has deactivated the audio session. It signals the SDK to release audio resources or update its internal state accordingly.

Note: This method is only relevant when using `OTAudioSessionManagerModeCallingServices`. In modes such as `OTAudioSessionManagerModeVideoChat`, this call will be ignored, as the SDK automatically manages the audio session lifecycle.

#### Declared In

`OTAudioKit.h`