Skip to main content
Prerequisites: Xcode 12+, iOS 11+, credentials from CometChat Dashboard

Prerequisites

RequirementVersion
Xcode12 or above
iOS11 or higher
Get your credentials from the CometChat Dashboard:
  • App ID
  • Region
  • Auth Key (for development)
Auth Key is for development/testing only. In production, generate Auth Tokens on your server using the REST API. Never expose Auth Keys in production client code.

Installation

CocoaPods

Create a Podfile in your project directory:
Add the CometChat SDK to your Podfile:
Install the dependency:
To update to the latest version:
CometChatSDK includes video calling components. We suggest you run on physical devices to avoid errors.

Swift Package Manager

  1. Open Xcode, go to the project’s General settings tab and select the project under Project in the left column.
  2. Go to the Swift packages tab and click on the + button.
  1. Enter the repository URL https://github.com/cometchat/chat-sdk-ios.git, set dependency rule to Up to Next Major Version with version 4.1.0, and click Add Package.
  1. Ensure CometChatSDK is checked in the Package Product column and click Add Package.

Request Authorization

Add justification strings to your app’s Info.plist for camera, microphone, and photo library access:

Setup Bitcode

Set Enable Bitcode to YES in your target’s build settings.

Swift Standard Libraries

Set "Always Embed Swift Standard Libraries" to Yes in your target’s build settings:

Set Header Search Path

Set Header Search Paths to $SDKROOT/usr/include/libxml2.

Initialization

The init() method initializes the SDK and must be called before any other CometChat method. Call it once at app startup, typically in didFinishLaunchingWithOptions: of your AppDelegate.
Replace APP_ID and APP_REGION with your credentials from the Dashboard.
CometChat.init() must be called before any other SDK method. Calling login(), sendMessage(), or registering listeners before init() will fail.

Parameters

ParameterTypeDescription
appIdStringYour CometChat App ID
appSettingsAppSettingsConfiguration object built with AppSettingsBuilder

AppSettings Options

MethodDescriptionDefault
setRegion(region:)Region where your app was created (us, eu, in)Required
subscribePresenceForAllUsers()Subscribe to presence events for all users
subscribePresenceForRoles(roles:)Subscribe to presence for specific roles
subscribePresenceForFriends()Subscribe to presence for friends only
autoEstablishSocketConnection(_:)Let SDK manage WebSocket connectionstrue
overrideAdminHost(adminHost:)Custom admin URL (dedicated deployment)
overrideClientHost(clientHost:)Custom client URL (dedicated deployment)

Presence Subscription

Choose how to subscribe to user presence (online/offline status):
See User Presence for more details.

WebSocket Connection

By default, the SDK manages WebSocket connections automatically. To manage them manually:
See Managing WebSocket Connections for manual control.

Next Steps

Authentication

Log in users with Auth Key or Auth Token

Send Messages

Send your first message