Building a Complete iOS Chat App with CometChat UI Kit

Learn how to build and launch a real-time iOS chat app in Swift using CometChat's UI Kit. This step-by-step tutorial covers installation, initialization, authentication, and a fully working chat interface along with a sample app to explore every feature.

Haris Kumar • Dec 8, 2025

Building an iOS chat app from scratch in Swift is a significant undertaking. Behind what looks like a simple message interface lies a set of complex, interdependent engineering problems:

  • Designing and maintaining a real-time messaging infrastructure that stays reliable on mobile networks

  • Handling message delivery, ordering, and offline sync across device transitions

  • Implementing presence indicators and typing status that update instantly across sessions

  • Building secure user authentication with proper token management

  • Designing native iOS UI components like conversation lists, message threads, media previews that meet iOS HIG standards

  • Scaling the backend as your user base grows, without re-architecting what you've already shipped

CometChat's iOS UI Kit for Swift handles all of that complexity. It provides pre-built, customizable iOS-based components backed by CometChat's real-time messaging infrastructure.

In this tutorial, you'll integrate the CometChat iOS UI Kit into a new Swift project, configure authentication, and have a working iOS chat app running on simulator or device in under an hour.

Why Use CometChat Instead of Building It Yourself?

Here's what building iOS chat looks like with and without CometChat:

Feature Traditional DIY With CometChat UI Kit
Real-time infrastructure
Build and operate WebSocket servers
Fully managed real-time messaging
Message delivery & sync
Custom delivery tracking, retry logic, and offline message queuing
Built-in delivery and read receipts, automatic sync across devices
Presence & typing
Manual event handling and subscriptions
Built-in and automatically updated
Authentication
Integrate custom auth + session handling
Simple UID login; Auth Token flow for production security
UI complexity
Build and maintain complex iOS Components
Pre-built UIKit components that follow iOS design patterns
Scalability
Requires careful architecture planning
Scales automatically with CometChat infra
Maintenance
Ongoing fixes and optimizations
Minimal maintenance
Calling
WebRTC setup, signaling server, codec negotiation, device permission management
Add the Calls SDK pod and enable calling in a few lines of config
Time to production
Months of engineering
Working chat app in under an hour

What You'll Build

By the end of this tutorial, you'll have a native Swift iOS app that supports:

  • User sign-in with a User ID

  • One-to-one messaging

  • Group chat (view and participate in group conversations)

  • Real-time messaging with typing indicators, online presence, and read/delivery receipts

  • Media messages and message reactions

  • Optional voice and video calling via the CometChat Calls SDK

Prerequisites

Knowledge

  • Swift fundamentals: variables, functions, classes, and optionals

  • iOS development basics: UIKit, view controllers, and Storyboards

  • Dependency management with CocoaPods or Swift Package Manager

  • Basic Xcode familiarity: project structure, build targets, and Info.plist

Tools

  • macOS with Xcode 12 or later installed (latest version strongly recommended)

  • CocoaPods installed on your Mac (sudo gem install cocoapods)

  • An iOS simulator or physical device running iOS 11 or later (iOS 13+ required if you plan to add calling features)

  • A CometChat account with an App ID, Region, and Auth Key

Getting Started

Step 1: Create a New iOS Application

Start with a clean Xcode project. Open Xcode and follow these steps:

  • Launch Xcode and select Create a new Xcode project.

  • Under iOS templates, choose App.

  • Fill in your project details: set the product name to CometChatApp, choose Storyboard as the interface, and select Swift as the language.

  • Choose a save location and click Create.

Confirm the app builds and runs on your simulator before adding any dependencies, this catches Xcode or signing issues early.

Step 2: Create a CometChat App and Collect Your Credentials

Every CometChat integration is tied to a CometChat app that manages your users, messages, and configuration. Create one now:

  • Go to the CometChat Dashboard and sign in (or create a free account).

  • Click Create App and give it a name.

  • Go to app credentials and copy your App ID, Region, and Auth Key.

Important: Your Auth Key grants full access to your CometChat app. Never commit it to version control or ship it in a production build.

Step 3: Install the CometChat iOS UI Kit

CocoaPods is the recommended approach for integrating the CometChat iOS UI Kit. In Terminal, navigate to your project directory and initialize CocoaPods if you haven't already:

Open the generated Podfile and add the CometChat UI Kit dependency:

Install the dependencies:

Important: After running pod install, always open the .xcworkspace file, not .xcodeproj. CocoaPods creates the workspace to link your project with the installed pods, and Xcode won't find the CometChat framework without it.

If you plan to enable calling features, add the Calls SDK to your Podfile alongside the UI Kit:

Run pod install again after updating the Podfile. The Calls SDK requires iOS 13 or later as your deployment target.

Step 4: Configure App Permissions

The CometChat UI Kit accesses the camera, microphone, and photo library for media messaging and voice/video calls. iOS requires you to declare these access reasons in Info.plist, the system displays these strings in the permission prompt shown to the user.

Open Info.plist and add the following keys:

Customize the description strings to match your app's specific use case and privacy policy. Apple may reject apps with generic or unclear permission descriptions during App Store review.

Step 5: Store Your CometChat Credentials

Create a dedicated Swift file to hold your CometChat app credentials. This keeps them in one place and makes them easy to find and update. Add a new file named AppConstants.swift to your project:

Production note: Auth Key login is suitable for development and testing. For production apps, generate a short-lived Auth Token on your backend using your CometChat REST API, then pass it to the client for login. This keeps your Auth Key off the device entirely.

Step 6: Initialize CometChat and Authenticate a User

CometChat initialization and user login both happen once at app startup in SceneDelegate.swift, before any chat UI is presented. Initialization registers your app credentials and connects to CometChat's real-time infrastructure. Login authenticates the user and establishes their session.

Replace the contents of SceneDelegate.swift with the following:

A few things worth noting about this setup:

  • Initialization must complete before login. The login call is nested inside the .success case of CometChatUIKit.init, this ensures the SDK is ready before attempting to authenticate.

  • UI updates run on the main thread. The DispatchQueue.main.async call is required, SDK callbacks return on a background thread, and UIKit operations must happen on the main thread.

  • [weak self] prevents retain cycles. The capture list in the async closure ensures the SceneDelegate can be deallocated normally.

  • Test users are pre-seeded. Every new CometChat app comes with five test users: cometchat-uid-1 through cometchat-uid-5. You can also create users via the CometChat Dashboard or REST API.

Step 7: Choose Your Chat Launch Pattern

The iOS UI Kit gives you three ways to present chat, depending on how chat fits into your app's navigation structure. The previous step already uses Option 1, the others are available for apps where chat is a secondary feature rather than the main screen.

Option 1 - Full conversations UI (already set up in Step 6)

CometChatConversationsWithMessages is the all-in-one component. It shows the conversation list on the left and opens the message thread when the user taps a conversation. This is the right choice if chat is the primary feature of your app.

Option 2 - Opens a specific one-to-one chat directly

Use this when you know which user to chat with upfront, for example, launching a chat with a support agent, a matched user in a marketplace, or a specific contact. Fetch the user object first, then present the Messages view:

Option 3 — Conversations list with custom tap handling

This option launches only the conversation list. You can define what happens when a user selects a conversation. Use this when you want to intercept the default interaction pattern and control what happens next, for example, navigating to a custom message screen or showing a paywall before opening the chat.

Step 8: Run and Test the App

With everything wired up, build and run the app to verify the full integration end-to-end:

  • Open CometChatApp.xcworkspace (not .xcodeproj) in Xcode.

  • Select a simulator or physical device from the scheme picker.

  • Click the Run button or press Cmd + R.

When the app launches, it will automatically initialize CometChat and log in with the UID you set in Step 6. You should see the conversations list screen load.

To test messaging end-to-end:

  • Run the app on two different simulators or devices, each logged in with a different UID (e.g., cometchat-uid-1 and cometchat-uid-2).

  • Open a conversation on one device and send a message, it should appear in real time on the other.

  • Verify typing indicators appear when one user is composing a message.

  • Check that read and delivery receipts update correctly.

If initialization fails, double-check that the App ID, Region, and Auth Key in AppConstants.swift exactly match the values in your CometChat Dashboard.

CometChat iOS Sample App

The official CometChat iOS sample app is a fully functional reference implementation built on the same UI Kit you've just integrated. It demonstrates the complete feature set, group management, calling, theming, and advanced messaging flows and is a practical starting point if you want to explore capabilities beyond what this tutorial covers.

Prerequisites

  • macOS with Xcode 12 or later installed

  • CocoaPods installed on your Mac

  • A CometChat account with an App ID, Region, and Auth Key

Installation

Clone the repository:

Navigate to the sample app directory:

Open the workspace (not the .xcodeproj):

Add your CometChat credentials to AppConstants.swift:

Select a simulator or physical device, then click Run (Cmd + R).

The sample app reference is hosted here.

Conclusion

You now have a native Swift iOS chat app backed by CometChat's real-time infrastructure, with conversation lists, message threads, typing indicators, and read receipts, without building or operating any of the backend that powers them. What typically takes months of iOS engineering to reach production quality was running in under an hour.

The iOS sample app is worth exploring next. It covers the full feature surface and gives you a solid reference for building those features into your own app.

Whether chat is the core of your product or something you're adding to an existing iOS app, the CometChat UI Kit is designed to fit into your navigation structure without taking it over. Happy building!

Haris Kumar

Lead Content Strategist , CometChat

Haris brings nearly half a decade of expertise in B2B SaaS content marketing, where he excels at developing strategic content that drives engagement and supports business growth. His deep understanding of the SaaS landscape allows him to craft compelling narratives that resonate with target audiences. Outside of his professional pursuits, Haris enjoys reading, trying out new dishes and watching new movies!