CallKit (available since iOS10) provides the ability to integrate call functionality into the iOS operating system.
This integration allows:
- Displaying the system screen of an incoming call (also over third-party applications)
- Displaying system screens of an active call or an unsuccessful call in case the phone is locked
- Resolving the situation of multiple calls from various applications that also use CallKit API integration (switching between calls on hold, an incoming call when on a call)
- Including call history
- Raising the priority of the call session to the maximum, making the session uninterrupted by other applications which use audio
- Taking into account the user’s blacklist settings, Do Not Disturb mode, Silent Mode, volume
- Using a special mode when working with the connected audio devices (playing on all devices at the same time) to notify of an incoming call; the mode is inaccessible through the public API
You can try the demo right away.
Outgoing call integration with CallKit API
In order to make an outgoing call, you need to initiate a custom action CXStartCallAction with the generated UUID and report this action to the CXCallController instance. You will also need to create a similar CXStartCallAction if you are handling call creation through the standard Phone application of the Recent Calls tab or using Siri.
After that, you have to transfer control to the CXProviderDelegate.provider (_: perform :) method by CXStartCallAction. Now you need to:
When the call is established, the VICallDelegate.call (_: didConnectWithHeaders :) method will be called. In the handler of this event, it is necessary to inform CallKit about the call status change for the corresponding system UI update.
- If you need to update the call information, create a CXCallUpdate object and use the CXProvider.reportCall method.
Incoming call integration with CallKit API
In this article, we don't cover the integration of CallKit and VoIP push notifications for incoming calls.
When an incoming call is received, control transfers to the delegate method VIClientCallManagerDelegate.client (_: didReceiveIncomingCall: withIncomingVideo: headers :), and the sequence of actions you should perform is as follows:
- Extract callKit UUID of the incoming call from the VICall instance.
- Retrieve the information about the caller from the VICall instance.
- Create a CXCallUpdate object and report on the new incoming call to the iOS call subsystem via the CallKit API.
The process of receiving an audio call will look like this:
The rest manipulations
All the user actions performed through the iOS call subsystem are presented in the form of descendant classes of CXAction. If the action is successful, you need to confirm it via the action.fulfill API. If an error occurred during the execution, reject it via the action.fail API.
Changing the audio session privileges with CallKit
The privileges of a call audio session escalate and de-escalate automatically when the iOS subsystem is using the CallKit API. It is necessary to forbid some other applications to interrupt the audio session. The call audio session itself crowds out other already active audio sessions (player and Siri, for example).
To ensure that the configuration of the Voximplant iOS SDK audio session does not conflict with the iOS audio privilege enhancement subsystem, it is extremely important to notify the Voximplant iOS SDK about the start and end of the audio session via a special API.
When starting the application, configure the audio session: