September 30, 2021

A Beginners Guide to the Apple iOS CallKit

Dev Lorenzo

A Beginners Guide to the Apple iOS CallKit

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.

Note that Apple provides lots of native kits (72) such as the AppKit, the ClockKit, the Cloudkit, the Mapkit, or even the Arkit.

Features of iOS CallKit

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?

We recommend trying to use CometChat Swift SDK, which makes it easy to access tons of useful features for your iOS app. Check out this documentation on adding Chat to your iOS App. You can also learn about our Calling feature. Also, here's a tutorial on how to build a fully-featured chat app in Swift:

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 -

1) Creating an Xcode iPhone App

As this advanced tutorial shows, creating an Xcode app is quite easy:

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:

class CXProvider

“An object that represents a telephony provider.”

protocol CXProviderDelegate

“A collection of methods that are called by a telephony provider object.”

class CXProviderConfiguration

“An encapsulation of the configuration of a provider object.”

class CXHandle

“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 class CXCallUpdate, “An encapsulation of new and changed information about a call”, or the class CXAnswerCallAction, “An encapsulation of the act of answering an incoming call”. Similar to it, you have the class CXStartCallAction, for the act of initiating an outgoing call or the class CXEndCallAction, 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.

The code is extracted from the Open Source Eric Giannini work, which you can find on GitHub or in his Medium tutorial

3) Other Functionalities

You also have, as detailed in this GitHub repo curated by WebsiteBeaver, other code templates regarding the callKit, such as to Connect a call, to receive a call when the app is closed with the pushkit, or to Customize the callKit. Some of the available customizations are the ability to change the ringtone, icon, call type (audio/video), embed timer that follows call time, whether or not the call is displayed in recent ones… 

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 Pro Swift 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! 

Check out here the documentation to add CometChat to your iOS Chat App. You can also learn about our Calling feature associated with our Core SDKs

Wrapping Up

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.

You can use a chat API service such as CometChat to easily create a text, voice, and video chat app. You can sign up to our developer dashboard and start building your chat app for free or get in touch with us for any questions or doubts.

About the Author

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!

Related Posts

Try Us for Free 

For as Long as You Like!