CometChat Developer Documentation

Welcome Ninja!

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Get Started    

Quick Start

The simplest voice, video and text chat SDK for your iOS app.

CometChat enables you to add voice, video and text chat to your iOS app in minutes! That's not all, CometChat has whiteboard, writeboard, real-time translation and more.

First, try out our sample chat app!

Before you add CometChat to your app, go ahead and download our sample app from GitHub. It gives you an indication of what to expect from CometChat.

Download Sample App (Swift)

Download Sample App (Objective C)

Once you download the sample app, update the License Key and API Key in the ViewController class in the project. (you can get these values from CometChat Admin Panel -> Settings -> API Key)

Please follow the steps mentioned in the README.md file to build and run the app.

Next, use these steps to quickly add CometChat to your app

All set to add CometChat to your iOS app ?? Just follow these steps and get the chat up and running in your app.

Add the SDK to your project

  1. Add Dependencies Manually:

Click on Targets → Your app name → and then the ‘Build Phases’ tab.
Expand ‘Link Binary With Libraries’ as given below and add the following frameworks.

a.SystemConfiguration.framework
b.MobileCoreServices.framework
c.CoreGraphics.framework
d.CFNetwork.framework
e.libxml2.tbd
f.libz.tbd
g.libsqlite3.tbd

  1. Add Dependencies Using CocoaPods:

You need to add the below lines to your project's podfile.

pod 'MessageSDKFramework' 
pod 'cometchat-ui' 
pod ‘Firebase/Auth’
pod ‘Firebase/Database’
pod ‘Firebase/Messaging’
pod 'MessageSDKFramework' 
pod 'cometchat-ui' 
pod ‘Firebase/Auth’,'~> 4.8.2'
pod ‘Firebase/Database’,'~> 4.8.2'

Cocoapods Setup

If you want to know about CocoaPods usage and installation you can refer to link below:
https://guides.cocoapods.org/using/using-cocoapods.
Also, please make sure you are using the latest version of Cocoapods.

  1. Add Linker Flag:

Click on Targets → Your app name → and then the ‘Build Settings’ tab.
Scroll down to the ‘Linking’ section, and double-click to the right of where it says ‘Other Linker Flags’. Click on the “+” button to add the following:

a. -ObjC

  1. Set Bitcode Enabled to NO:

Click on Targets → Your app name → and then the ‘Build Settings’ tab. Scroll down to the 'Build Options' section, and set the 'Enable Bitcode' to 'NO'.

  1. Additional Setup for Swift:

In order for Xcode to use an Objective-C based framework in Swift, it needs to have a bridging header file. We have included a bridging header file in our framework. To link to it, you must open the build settings for your new target, and search for the Objective-C Bridging Header setting. You must then provide the path to the CometChat-Bridging-Header.h.

The path should be something similar to the one shown below :
$(SRCROOT)/Pods/cometchat-ui/cometchat-ui/cometchat-ui.framework/Versions/A/Headers/CometChat-Bridging-Header.h

Initialize the Chat

The first step to launch the Chat in your iOS application is to initialize the CometChat module. You need to use the below method to do so:

let cometChat : CometChat = CometChat();
let licenseKey: String = "COMETCHAT-XXXXX-XXXXX-XXXXX-XXXXX";
let apiKey: String= "xxxxxxxxxxxxxxxxxxxxxx";

self.cometChat.initializeCometChat("", licenseKey:licenseKey, apikey:apiKey, isCometOnDemand:true, 
 
 				success: {(response) in
       
            
        },failure:{(error) in
            

        })
CometChat *cometChat = [[CometChat alloc]init];
NSString* licenseKey = @"COMETCHAT-XXXXX-XXXXX-XXXXX-XXXXX";
NSString* apiKey = @"xxxxxxxxxxxxxxxxxxxxxx";

[cometChat initializeCometChat:@"" licenseKey:licenseKey apikey:apiKey isCometOnDemand:YES 
        success:^(NSDictionary *response) {

        } failure:^(NSError *error) {

        }];

The licenseKey and apiKey is available at CometChat Admin Panel -> Settings ->API Key.

Necessary Imports in case of Objective C:

Please make sure to import the below lines for using CometChat SDK:
import <MessageSDKFramework/CometChat.h>
import <cometchat-ui/readyUIFIle.h>

No imports are necessary in case of Swift

Login To Chat

The next step to launch the chat is to log in the user. CometChat provides a method loginWithUid() to log the user into chat. We have already added 5 demo users to your account with the UIDs SUPERHERO1,SUPERHERO2,SUPERHERO3,SUPERHERO4, and SUPERHERO5. You can use any of the users to log in. If you would like more information regarding User management, you can get it here.

let UID : String = "SUPERHERO1";

 cometChat.login(withUID:UID, 
 
success:{(response) in                   
                    
 },
failure:{(error) in
                    
});
NSString* UID = @"SUPERHERO1";

[cometChat loginWithUID:UID success:^(NSDictionary *response) {

    } failure:^(NSError *error) {

    }];

Keep in mind

The initializeCometChat and the loginWithUid methods must only be called once in the entire scope of the app. We suggest, you call the initializeCometChat method on app startup and call the loginWithUID() method once the user successfully logs in to your application.

Launch Chat

In order to launch the chat, you need to use the launchCometChat method.

let isFullScreen : Bool = true;
let readyUI: readyUIFIle = readyUIFIle();
self.readyUI.launchCometChat(isFullScreen, observer: self, userInfo: { (response) in
                        
}, groupInfo: { (response) in
                        
}, onMessageReceive: { (response) in
                        
}, success: { (response) in
                        
}, failure: { (error) in
                        
}, onLogout: { (response) in
                        
})
BOOL isFullScreen = YES;
readyUIFIle* readyUIFile = [[readyUIFIle alloc]init];
[readyUIFile launchCometChat:IsFullScreen observer:self userInfo:^(NSDictionary *response) {

    } groupInfo:^(NSDictionary *response) {

    } onMessageReceive:^(NSDictionary *response) {

    } success:^(NSDictionary *response) {

    } failure:^(NSError *error) {

    } onLogout:^(NSDictionary *response) {

    }];

CometChat also provides you with other options such as launch the chat window for a particular user directly or for a particular group. For more information, please check here.

You're all set! Go ahead and explore

Now that you have CometChat running in your app, you can tweak it further. Explore the other sections to learn more.

Quick Start

The simplest voice, video and text chat SDK for your iOS app.