We all know the most famous tech brand, Apple, and some of us also know they have well-curated documentation for developers, but do you truly understand it, especially the CallKit? In this article, we will explain what the Apple iOS CallKit is, and let you learn about its major components and features. We will then look at how to build a chat, voice, or video app using it, going further the Apple documentation. Let’s start!
What is CallKit?
First of all, I guess you know that the kit works in Swift and Objective-C, the only two programming languages that iOS supports. We recommend learning and using the first if you can, as we consider Objective-C a dying language that will probably disappear in the following 5-10 years.
Back to our explanation, the CallKit is a framework that "displays the system-calling UI for your app’s VoIP (Voice over Internet Protocol) services and coordinates your calling services with other apps and the system”.
Introduced in 2016 (iOS 10), we use it to "integrate calling services with other call-related apps on the system." To understand the concept in a more practical way, imagine a service like WhatsApp or Skype, which are popular personal VoIP apps. They have a proper back-end, but they rely on the Apple Kit to give the front-end a "native look and feel" on Apple devices. The main objective is to “enable third-party developers to extend Apple services”, to make calls feel like part of iOS.
The Call Kit provides lots of features to allow the app to be as user-centered as possible. Besides allowing the user to send and receive calls on a native interface, it also has a lot of useful features, such as:
Locked and Unlocked State when receiving calls (additional security and user responsiveness layer). The calls take over the Home (unlocked state) and also the Lock screen rather than being basic push notifications.
Allowing the user to start a call within the VoIP app, via a link, directly in the Apple phone app (as WhatsApp does) or even with Siri (using voice).
System-level integration features, such as integrability with Do-Not-Disturb, Mute, or vibration-only modes.
Different call blocking features, starting with matching the in-app number of the sender with the receiver iPhone user blocked list. It also allows the app to insert a custom list of blocked numbers that is, for example, in relation to the back-end, and so direct interactions within the app.
Identification of the caller to extract and display his name from the saved contacts list. First, it consults and shows the username as it is saved in the app and then it goes through the regular phone app contact database. This feature is especially useful in social networks, where the in-social name differs from the one used in the phone app.
Notification of external interruptions that allows the app to correctly terminate the call. Examples are when the user answers to another call (natively or with another service) or simply has connectivity problems.
Note also that experienced Apple developers built the framework with user security and privacy at their core, which is more trustable than building things in-house.
How to Build a Voice/Video Chat for iOS With the Kit?
Apple’s event-based iOS Call Kit allows you to manage the whole front-end call system in a few lines of code, which is way more powerful than the original hard-coded push notifications. To test it, we will now simulate a call on both the sender and the receiver phone. Follow these steps -
After downloading Xcode, if you haven't already done so, you should click on “Create a new Xcode project” in the welcome window. You can create any kind of app you want, even if in this tutorial we will use a single view app, that you can then apply to your app. After inserting basic routine information, you should have access to the main window of your app. You can start by building and running it as a test.
Note also that, to overcome an error (The operation couldn’t be completed - com.apple.CallKit.error.requesttransaction error 1), you should tell Xcode you are creating a VoIP app. To do so, under Signing & Capabilities section, capability.
Search for background Modes and select “Voice over IP”:
2) Receive a Call
First, understand that the callKit works with classes - you can find details of all classes in the Apple documentation. The most important ones are:
“An object that represents a telephony provider.”
“A collection of methods that are called by a telephony provider object.”
“An encapsulation of the configuration of a provider object.”
“A means by which a call recipient can be reached, such as a phone number or email address.”
You have also classes that provide information about the call, for example, the classCXCallUpdate, “An encapsulation of new and changed information about a call”, or the classCXAnswerCallAction, “An encapsulation of the act of answering an incoming call”. Similar to it, you have the classCXStartCallAction, for the act of initiating an outgoing call or the classCXEndCallAction, for the act of ending a call. reportNewIncomingCall is used to display the call.
If the delegate methods are not there in the memory the call kit will not work, for that it’s preferable to implement the call kit delegate methods in AppDelegate.
3) Send a Call
Sending a call is quite similar to receiving a call, and, especially if you understood the above code correctly, it can be considered not so difficult nor time-consuming.
What role does Call Kit play in building a chat app for iOS?
A huge percentage of chat mobile apps also allow users the possibility to call each other. And vice-versa, lots of calling apps require to have an embed chat. For example, Whatsapp and Skype, that provide both features. Even if your app is not centered on the call feature, but you want to implement it, you should also consider adding a chat service to it, as it is usually better for your users to have both.
For that, we recommend trying to use CometChat ProSwift SDK, which makes you easily access tons of useful features for your future successful apps. With it, you will have access to One-on-one and Group Conversations (chat) and Voice & Video Calling, as push and email notification, End-to-End Encryption, or even Real-time Translation!
The main objective of the Apple CallKit is to make calls feel like part of iOS. The core features are the ability to receive calls in both locked and unlocked state, system-level integration, the ability to block and identify calls, and many more.
You can easily create an iOS app with Swift or Objective-C in Xcode and use starting code to receive, send and connect calls. You can also customize the CallKit and receive a call when the app is closed.
Dev Lorenzo is a young man working to be a full stack developer. His goal is to create a programming community for exchanging ideas and foster innovation. Blogger at dev.to, he sends a weekly newsletter about programming and productivity tips!