I want to integrate with my app
- Get your application keys
- Add the CometChat dependency
- Initialize CometChat
- Register or Login your user
- Integrate our UI Kits
I want to explore iOS sample apps.
Import the app into Xcode and follow the steps mentioned in theREADME.md
file.
Download Swift Chat App
Download Obj-c Chat App
Download iOS SDK from Github
Get your Application Keys
Signup for CometChat and then:- Create a new app
- Head over to the API & Auth Keys section and note the Auth Key, App ID & Region
Minimum Requirement
- Xcode 12 or above
- iOS 11 or higher
Add the CometChat Dependency
CocoaPods
We recommend using CocoaPods, as they are the most advanced way of managing iOS project dependencies. Open a terminal window, move to your project directory, and then create aPodfile
by running the following command.
- CometChatPro SDK supports installation through Cocoapods and SPM both. Currently, we are supporting Xcode 12 or above versions of Xcode.
- CometChatPro SDK includes video calling components. We suggest you run on physical devices to avoid errors.
v3.0.2+ onwards, Voice & Video Calling functionality has been moved to a separate framework. In case you do plan to use the calling feature, please add the Calling framework
pod 'CometChatCalls', '3.0.0'
in your app Podfile.CometChatPro
framework through CocoaPods.
CometChatPro
by command.
Swift Packages
To install Swift Packages you can use Xcode package manager.- Open Xcode, go to the project’s General settings tab and select the project under Project in the left column.
- Go to the Swift packages tab and click on the + button.

- Once the pop-up appears, enter the github repository address in the search bar
https://github.com/cometchat/chat-sdk-ios.git
and set dependency rule toUp to Next Major Version
and set version as3.0.919
. Then click on the Add Package button.

- CometChatPro must be checked in the Package Product column and click on Add Package. This will add Package Dependencies menu in Xcode.

Setup Bitcode
You can set the Enable Bitcode setting to YES present in build settings in your XCode project.
If you are using CometChat Pro SDK having the version less than 2.0.8, then you need to set Enable Bitcode to NO
Swift Standard Libraries
CometChatPro
framework build on Swift, you have to ensure the required libraries are embedded. This can be done by setting the “Always Embed Swift Standard Libraries”
checkbox in your target’s build settings to “Yes”:

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

Excluded Architecture
For Xcode 12 and above, we need to add arm64 in the excluded architecture of build settings as Apple supports only arm architecture for simulators and actual devices. No support provided for X86_64 and i386 architectures.
Setting for build for active architecture
In Build Settings, enable active architecture to Yes

Initialize CometChat
Theinit()
method initializes the settings required for CometChat.
The init()
method takes the below parameters:
- appID - You CometChat App ID
- appSettings - An object of the AppSettings class can be created using the AppSettingsBuilder class. The region field is mandatory and can be set using the
setRegion()
method.
AppSettings
class allows you to configure three settings:
- Region: The region where you app was created.
- Presence Subscription: Represents the subscription type for user presence (real-time online/offline status)
- autoEstablishSocketConnection(boolean value): This property takes a boolean value which when set to true informs the SDK to manage the web-socket connection internally. If set to false, it informs the SDK that the web-socket connection will be managed manually. The default value for this parameter is true. For more information on this, please check the Managing Web-Socket connections manually section. The default value for this property is true.
- overrideAdminHost(adminHost: string): This method takes the admin URL as input and uses this admin URL instead of the default admin URL. This can be used in case of dedicated deployment of CometChat.
- overrideClientHost(clientHost: string): This method takes the client URL as input and uses this client URL instead of the default client URL. This can be used in case of dedicated deployment of CometChat.
didFinishLaunchingWithOptions:
method of the AppDelegate
class.
appId
with your CometChat App ID in the above code.
Register and Login your User
Once initialization is successful, you will need to create a user. To create users on the fly, you can use thecreateUser()
method. This method takes a User
object and the API Key
as input parameters and returns the created User
object if the request is successful.
login()
method.
The login method needs to be called in the following scenarios:
- When the user is logging to the App for the first time.
- If the
CometChat.getLoggedInUser()
function returns nil.
Kindly, make sure you add the check of CometChat.getLoggedInUser() function in your app where you check the App’s user login status. In case it returns nil then you need to call the Login method inside it.
API_KEY
with your CometChat ApiKey in the above code.
Sample UsersWe have set up 5 users for testing having UIDs:
cometchat-uid-1
, cometchat-uid-2
, cometchat-uid-3
, cometchat-uid-4
and cometchat-uid-5
.login()
method returns the User object containing all the information of the logged in user.
UID can be alphanumeric with underscore and hyphen. Spaces, punctuation and other special characters are not allowed.