Skip to main content
FieldValue
PackageCometChatUIKitSwift
Version5.1.9
RequirementsXcode 16+, iOS 13.0+, Swift 5.0+
InitCometChatUIKit.init(uiKitSettings:) — must complete before login()
LoginCometChatUIKit.login(uid:) — must complete before rendering components
Orderinit()login() → render. Breaking this order = blank screen
Auth KeyDev/testing only. Use Auth Token in production
CallingOptional. Install CometChatCallsSDK 4.2.2 to enable
DependenciesCometChatSDK 4.1.0 (installed automatically)
This guide walks you through adding CometChat to an iOS app. By the end you’ll have a working chat UI.

Prerequisites

You need three things from the CometChat Dashboard:
CredentialWhere to find it
App IDDashboard → Your App → Credentials
Auth KeyDashboard → Your App → Credentials
RegionDashboard → Your App → Credentials (e.g. us, eu, in)
You also need:
  • Xcode 16 or later
  • iOS device or simulator running iOS 13.0+
  • Swift 5.0+
  • macOS
Auth Key is for development only. In production, generate Auth Tokens server-side via the REST API and use loginWithAuthToken(). Never ship Auth Keys in client code.

Step 1 — Create an iOS Project

Open Xcode and create a new project:
  1. Select iOS App in the template picker and click Next
  2. Enter your project name and bundle identifier
  3. Select Storyboard for Interface
  4. Select Swift for Language

Step 2 — Install the UI Kit

  1. Create a Podfile in your project root:
pod init
  1. Add CometChat to your Podfile:
Podfile
platform :ios, '13.0'
use_frameworks!

target 'YourApp' do
  pod 'CometChatUIKitSwift', '5.1.9'
  
  # Optional: Voice/Video Calling
  pod 'CometChatCallsSDK', '4.2.2'
end
  1. Install dependencies:
pod install --repo-update
  1. Close the .xcodeproj file and open the .xcworkspace file instead. CocoaPods creates a workspace that includes your project and the installed pods.
Always open the .xcworkspace file after installing pods — opening the .xcodeproj will cause build errors. Having issues? See CocoaPods Troubleshooting.

Step 3 — Configure Permissions

Add these keys to your Info.plist for media messaging:
Info.plist
<key>NSCameraUsageDescription</key>
<string>Allow access to the camera to capture photos and videos.</string>

<key>NSMicrophoneUsageDescription</key>
<string>Enable microphone access for voice and video communication.</string>

<key>NSPhotoLibraryAddUsageDescription</key>
<string>Allow saving photos and videos to your device's photo library.</string>

<key>NSPhotoLibraryUsageDescription</key>
<string>Grant access to select and upload photos from your library.</string>
Also disable User Script Sandboxing in Build Settings to ensure WebView can load scripts for collaborative tools:
  1. Select your project in the Navigator
  2. Select your app target
  3. Go to Build Settings tab
  4. Search for “User Script Sandboxing”
  5. Set it to No

Step 4 — Initialize & Login

Add this to your SceneDelegate.swift. Init must complete before login, and login must complete before rendering any UI.
SceneDelegate.swift
import UIKit
import CometChatUIKitSwift
import CometChatSDK

class 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 }

        let uikitSettings = UIKitSettings()
            .set(appID: "APP_ID")        // Replace with your App ID
            .set(region: "REGION")       // Replace with your Region
            .set(authKey: "AUTH_KEY")    // Replace with your Auth Key (dev only)
            .subscribePresenceForAllUsers()
            .build()

        CometChatUIKit.init(uiKitSettings: uikitSettings) { result in
            switch result {
            case .success:
                debugPrint("CometChat initialized")
                
                let uid = "cometchat-uid-1"  // Test user
                
                CometChatUIKit.login(uid: uid) { loginResult in
                    switch loginResult {
                    case .success:
                        debugPrint("Login successful")
                        
                        // ✅ Option 1: Launch One-to-One or Group Chat Screen
                        // DispatchQueue.main.async { 
                        //     self.setUpOneOneOrGroupConversation(windowScene: windowScene, uid: "cometchat-uid-2")
                        // }

                        // ✅ Option 2: Launch Conversation List + Message View
                        // DispatchQueue.main.async {
                        //     self.setupConversationsView(windowScene: windowScene)
                        // }

                        // ✅ Option 3: Launch Tab-Based Chat Experience
                        // DispatchQueue.main.async {
                        //     self.setupTabbedView(windowScene: windowScene)
                        // }
                        
                    case .onError(let error):
                        debugPrint("Login failed: \(error.description)")
                    @unknown default:
                        break
                    }
                }
                
            case .failure(let error):
                debugPrint("Init failed: \(error.localizedDescription)")
            }
        }
    }
}
For development, use one of the pre-created test UIDs: cometchat-uid-1 · cometchat-uid-2 · cometchat-uid-3 · cometchat-uid-4 · cometchat-uid-5 Or create new users via the CometChat Dashboard, SDK method, or REST API. After running the app, you should see:
"CometChat initialized"
"Login successful"
init() must complete before you call login(). If you call login() before init completes, it will fail silently.
For production, use loginWithAuthToken() instead of Auth Key. Generate tokens server-side via the REST API.
Having issues? Check the Troubleshooting Guide for common problems and solutions.

Step 5 — Choose a Chat Experience

Integrate a conversation view that suits your app’s UX. Each option below includes a step-by-step guide.

Conversation List + Message View

Two-panel layout — conversation list with push navigation to messages. Think iMessage or WhatsApp.
  • Push-based navigation between conversations and messages
  • Supports one-to-one and group chats
  • Real-time sync with CometChat event listeners
  • Session-aware — message states persist across app sessions

Build Conversation List + Message View

Step-by-step guide to build this layout

One-to-One / Group Chat

Single chat window — no sidebar. Good for support chat, contextual messaging, or focused conversations.
  • Dedicated chat window for one-on-one or group messaging
  • No conversation list — users go directly into the chat
  • Full-screen experience optimized for mobile
  • Ideal for support workflows, community replies, or invitations

Build One-to-One / Group Chat

Step-by-step guide to build this layout

Tab-Based Chat

Tabbed navigation — Chats, Calls, Users, Groups in separate tabs. Good for full-featured apps.
  • UITabBarController or SwiftUI TabView navigation
  • Full-screen messaging within each tab
  • Modular UI — isolated controllers for each tab
  • Scales well for adding future features like notifications or settings

Build Tab-Based Chat

Step-by-step guide to build this layout

Build Your Own Chat Experience

Need full control over the UI? Use individual components, customize themes, and wire up your own layouts.
  • Sample App — Working reference app to compare against
  • Components — All prebuilt UI elements with customization options
  • Core Features — Messaging, real-time updates, and other capabilities
  • Theming — Colors, fonts, dark mode, and custom styling
  • Build Your Own UI — Skip the UI Kit entirely and build on the raw SDK

Next Steps

Components Overview

Browse all prebuilt UI components

Theming

Customize colors, fonts, and styles

Core Features

Chat features included out of the box

Methods

SDK methods and API reference