Integrate CallKit into the UI Library

The Azure Communication Services UI Library provides out-of-the-box support for CallKit. Developers can provide their own configuration for CallKit to be used for the UI Library.

In this article, you learn how to set up CallKit correctly by using the UI Library in your application.

Important

This feature of Azure Communication Services is currently in preview.

Preview APIs and SDKs are provided without a service-level agreement. We recommend that you don't use them for production workloads. Some features might not be supported, or they might have constrained capabilities.

For more information, review Supplemental Terms of Use for Microsoft Azure Previews.

Prerequisites

For more information, see the open-source iOS UI Library and the sample application code.

Set up CallKit integration

The Azure Communication Services Calling iOS SDK supports CallKit integration. You can enable this integration in the UI Library by configuring an instance of CallCompositeCallKitOption. For more information, see Integrate with CallKit.

Specify call recipient info for incoming and outgoing calls

To specify call recipient info, create an instance of CallCompositeCallKitRemoteInfo.

Assign a value for displayName to customize the display name for call recipients. The value specified in displayName is exactly how it appears in the last-dialed call log.

Also assign the cxHandle value. It's what the application receives when the user calls back on that contact.

let cxHandle = CXHandle(type: .generic, value: "VALUE_TO_CXHANDLE")
var displayName = "DISPLAY_NAME"
let callKitRemoteInfo = CallCompositeCallKitRemoteInfo(displayName: displayName, cxHandle: cxHandle)

If you don't provide CallCompositeCallKitRemoteInfo, the participant identifier's raw value is displayed by default.

Configure providers

As required, provide a CallCompositeCallKitRemoteInfo instance to CallCompositeCallKitOption. The UI Library also provides a default provider: CallCompositeCallKitOption.getDefaultCXProviderConfiguration(). For more information, see the Apple developer documentation about CXProviderConfiguration.

let cxProvider = CallCompositeCallKitOption.getDefaultCXProviderConfiguration()

Configure an audio session

Configure an audio session to be called before placing or accepting incoming call and before resuming a call that's on hold. For more information, see the Apple developer documentation about AVAudioSession.

public func configureAudioSession() -> Error? {
    let audioSession = AVAudioSession.sharedInstance()
    var configError: Error?
    do {
        try audioSession.setCategory(.playAndRecord)
    } catch {
        configError = error
    }
    return configError
}

Enable CallKit

To enable CallKit, create an instance of CallCompositeCallKitOption and provide it to RemoteOptions.

let isCallHoldSupported = true // enable call hold (default is true)
let callKitOptions = CallCompositeCallKitOption(
    cxProvideConfig: cxProvider,
    isCallHoldSupported: isCallHoldSupported,
    remoteInfo: callKitRemoteInfo,
    configureAudioSession: configureAudioSession
)

let remoteOptions = RemoteOptions(
    ..., // Other options for Azure Communication Service
    callKitOptions: callKitOptions
)

Next steps