Complete guide to adding voice and video calling to iOS apps with CometChat UI Kit - production-ready code included
AI Integration Quick Reference
{ "category": "calling", "features": [ {"name": "voiceCalling", "description": "One-on-one and group audio calls", "component": "CometChatCallButtons", "enabledByDefault": true}, {"name": "videoCalling", "description": "One-on-one and group video calls", "component": "CometChatCallButtons", "enabledByDefault": true}, {"name": "callLogs", "description": "View call history with metadata", "component": "CometChatCallLogs", "enabledByDefault": true}, {"name": "incomingCall", "description": "Handle incoming call UI with accept/reject", "component": "CometChatIncomingCall", "enabledByDefault": true}, {"name": "outgoingCall", "description": "Display outgoing call screen while connecting", "component": "CometChatOutgoingCall", "enabledByDefault": true}, {"name": "ongoingCall", "description": "Active call interface with controls", "component": "CometChatOngoingCall", "enabledByDefault": true} ], "sdkDependencies": { "required": "CometChatCallsSDK 5.0.4 (SPM, Up to Next Major)", "permissions": ["NSCameraUsageDescription", "NSMicrophoneUsageDescription"] }, "relatedComponents": ["CometChatCallButtons", "CometChatCallLogs", "CometChatIncomingCall", "CometChatOutgoingCall", "CometChatOngoingCall"]}
Overview
Add one-on-one and group audio/video calling to your iOS app. Once integrated, call buttons automatically appear in chat headers, and incoming/outgoing call screens are handled for you.
Quick Setup
1
Add Dependencies
In Xcode, go to File → Add Package Dependencies and add both packages with Up to Next Major Version:
Package URL
Version
Product
https://github.com/cometchat/cometchat-uikit-ios
5.2.3
CometChatUIKitSwift
https://github.com/cometchat/calls-sdk-ios
5.0.4
CometChatCallsSDK
The UI Kit brings in CometChatSDK itself, and requires iOS 15.1+. CocoaPods stops at UI Kit 5.1.18, so use Swift Package Manager for current releases.
2
Add Permissions
Add to Info.plist:
<key>NSCameraUsageDescription</key><string>Camera access required for video calls</string><key>NSMicrophoneUsageDescription</key><string>Microphone access required for voice and video calls</string>
3
Initialize CometChat
In SceneDelegate.swift:
import CometChatUIKitSwiftfunc scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } let uikitSettings = UIKitSettings() .set(appID: "YOUR_APP_ID") .set(authKey: "YOUR_AUTH_KEY") .set(region: "YOUR_REGION") // "us", "eu", or "in" .build() CometChatUIKit.init(uiKitSettings: uikitSettings) { result in switch result { case .success: CometChatUIKit.login(uid: "cometchat-uid-1") { loginResult in switch loginResult { case .success: // Calling is now enabled automatically print("✅ Ready for calls") case .onError(let error): print("❌ Login failed: \(error.description)") @unknown default: break } } case .failure(let error): print("❌ Init failed: \(error.localizedDescription)") } }}
That’s it! Call buttons appear in CometChatMessageHeader automatically.
Production-Ready Implementation
Complete app with calling, chat, and call history:
SceneDelegate.swift
MainTabBarController.swift
import UIKitimport CometChatUIKitSwiftimport CometChatSDKclass SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } // Initialize CometChat let uikitSettings = UIKitSettings() .set(appID: "YOUR_APP_ID") .set(authKey: "YOUR_AUTH_KEY") .set(region: "YOUR_REGION") .subscribePresenceForAllUsers() .build() CometChatUIKit.init(uiKitSettings: uikitSettings) { [weak self] result in switch result { case .success: print("✅ CometChat initialized") self?.loginAndSetupUI(windowScene: windowScene) case .failure(let error): print("❌ Init failed: \(error.localizedDescription)") } } } private func loginAndSetupUI(windowScene: UIWindowScene) { CometChatUIKit.login(uid: "cometchat-uid-1") { [weak self] result in switch result { case .success: print("✅ Logged in") DispatchQueue.main.async { self?.setupMainInterface(windowScene: windowScene) } case .onError(let error): print("❌ Login failed: \(error.description)") @unknown default: break } } } private func setupMainInterface(windowScene: UIWindowScene) { let tabBar = MainTabBarController() window = UIWindow(windowScene: windowScene) window?.rootViewController = tabBar window?.makeKeyAndVisible() }}
import UIKitimport CometChatUIKitSwiftclass MainTabBarController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() setupTabs() setupAppearance() } private func setupTabs() { // Chats Tab - with calling enabled let chatsVC = ChatListVC() // your own list + chat screen — see /ui-kit/ios/ios-tab-based-chat let chatsNav = UINavigationController(rootViewController: chatsVC) chatsNav.tabBarItem = UITabBarItem( title: "Chats", image: UIImage(systemName: "message"), selectedImage: UIImage(systemName: "message.fill") ) // Calls Tab - call history let callsVC = CometChatCallLogs() callsVC.set(onItemClick: { [weak self] callLog in self?.handleCallLogTap(callLog) }) let callsNav = UINavigationController(rootViewController: callsVC) callsNav.tabBarItem = UITabBarItem( title: "Calls", image: UIImage(systemName: "phone"), selectedImage: UIImage(systemName: "phone.fill") ) // Users Tab let usersVC = ChatListVC() // your own list + chat screen — see /ui-kit/ios/ios-tab-based-chat let usersNav = UINavigationController(rootViewController: usersVC) usersNav.tabBarItem = UITabBarItem( title: "Users", image: UIImage(systemName: "person.2"), selectedImage: UIImage(systemName: "person.2.fill") ) // Groups Tab let groupsVC = ChatListVC() // your own list + chat screen — see /ui-kit/ios/ios-tab-based-chat let groupsNav = UINavigationController(rootViewController: groupsVC) groupsNav.tabBarItem = UITabBarItem( title: "Groups", image: UIImage(systemName: "person.3"), selectedImage: UIImage(systemName: "person.3.fill") ) viewControllers = [chatsNav, callsNav, usersNav, groupsNav] } private func setupAppearance() { tabBar.tintColor = .systemBlue tabBar.backgroundColor = .systemBackground } private func handleCallLogTap(_ callLog: CallLog) { // Get the other user from call log let loggedInUser = CometChat.getLoggedInUser() var otherUserUID: String? if let initiator = callLog.initiator as? CallUser, initiator.uid != loggedInUser?.uid { otherUserUID = initiator.uid } else if let receiver = callLog.receiver as? CallUser { otherUserUID = receiver.uid } guard let uid = otherUserUID else { return } // Fetch user and open chat CometChat.getUser(UID: uid) { [weak self] user in DispatchQueue.main.async { let messagesVC = MessagesVC() // your own VC — see /ui-kit/ios/ios-conversation messagesVC.user = user if let nav = self?.selectedViewController as? UINavigationController { nav.pushViewController(messagesVC, animated: true) } } } onError: { error in print("Error: \(error?.errorDescription ?? "")") } }}
import UIKitimport CometChatUIKitSwiftimport CometChatSDKclass ChatHeaderViewController: UIViewController { var user: CometChat.User! override func viewDidLoad() { super.viewDidLoad() setupCallButtons() } private func setupCallButtons() { let callButtons = CometChatCallButtons() callButtons.user = user // Customize actions callButtons.onVoiceCallClick = { user, group in print("Voice call to: \(user?.name ?? group?.name ?? "")") }) callButtons.onVideoCallClick = { user, group in print("Video call to: \(user?.name ?? group?.name ?? "")") }) callButtons.set(onError: { error in print("Error: \(error.errorDescription)") }) // Add to navigation bar let hostingController = UIHostingController(rootView: callButtons) addChild(hostingController) navigationItem.rightBarButtonItem = UIBarButtonItem(customView: hostingController.view) }}
Handle Incoming Calls
Incoming calls are handled automatically. For custom handling:
Swift
import CometChatSDKclass CallHandler: NSObject, CometChatCallDelegate { static let shared = CallHandler() func registerForCalls() { CometChat.calldelegate = self } // Called when receiving an incoming call func onIncomingCallReceived(incomingCall: CometChat.Call?, error: CometChat.CometChatException?) { guard let call = incomingCall else { return } print("📞 Incoming call from: \(call.sender?.name ?? "")") print("Call type: \(call.callType == .audio ? "Audio" : "Video")") // The UI Kit automatically shows the incoming call screen // Add custom logic here if needed } // Called when an outgoing call is accepted func onOutgoingCallAccepted(acceptedCall: CometChat.Call?, error: CometChat.CometChatException?) { guard let call = acceptedCall else { return } print("✅ Call accepted: \(call.sessionId ?? "")") } // Called when an outgoing call is rejected func onOutgoingCallRejected(rejectedCall: CometChat.Call?, error: CometChat.CometChatException?) { guard let call = rejectedCall else { return } print("❌ Call rejected: \(call.sessionId ?? "")") } // Called when an incoming call is cancelled func onIncomingCallCancelled(canceledCall: CometChat.Call?, error: CometChat.CometChatException?) { guard let call = canceledCall else { return } print("📵 Call cancelled: \(call.sessionId ?? "")") } // Called when a call ends func onCallEnded(endedCall: CometChat.Call?, error: CometChat.CometChatException?) { guard let call = endedCall else { return } print("📴 Call ended: \(call.sessionId ?? "")") }}// Register in AppDelegate or SceneDelegate// CallHandler.shared.registerForCalls()
Calling Components Reference
CometChatCallButtons
Renders voice and video call buttons.
let callButtons = CometChatCallButtons()callButtons.user = user // or callButtons.group = group// CallbackscallButtons.onVoiceCallClick = { user, group in })callButtons.onVideoCallClick = { user, group in })callButtons.set(onError: { error in })
CometChatIncomingCall
Displays incoming call screen with accept/reject options.
let incomingCall = CometChatIncomingCall()incomingCall.set(call: call)incomingCall.set(onAcceptClick: { call in })incomingCall.set(onCancelClick: { call in })
CometChatOutgoingCall
Displays outgoing call screen while waiting for answer.
let outgoingCall = CometChatOutgoingCall()outgoingCall.set(call: call)outgoingCall.set(onCancelClick: { call in })
CometChatCallLogs
Displays call history. See Call Logs for full documentation.
let callLogs = CometChatCallLogs()callLogs.set(onItemClick: { callLog in })