CometChat is a platform for integrating voice, video & text messaging experiences into your websites, web apps and mobile apps


Keywords
chat, ios, messaging, sdk, swift
License
MIT
Install
pod try CometChatSDK

Documentation


CometChat iOS Chat SDK



CometChat enables you to add voice, video & text chat for your website & app.


Prerequisites ⭐

Before you begin, ensure you have met the following requirements:

✅   You have installed the latest version of Xcode. (Above Xcode 12 Recommended)

✅   iOS Chat SDK works for the iOS devices from iOS 11 and above.


Installing iOS Chat SDK

1. Setup 🔧

To install iOS Chat SDK, you need to first register on CometChat Dashboard. Click here to sign up.

i. Get your Application Keys 🔑

  • Create a new app
  • Head over to the Quick Start or API & Auth Keys section and note the App ID, Auth Key, and Region.

ii. Add the CometChatPro Dependency

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 a Podfile by running the following command

Create podfile using below command.

$ pod init

Add the following lines to the Podfile.

________________________________________________________________

For Xcode 12 and above:

platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
     pod 'CometChatPro', '2.4.1'
end
________________________________________________________________

v2.4.1+ onwards, Voice & Video Calling functionality has been moved to a separate framework. Please add the following pod to your app Podfile in case you plan on using the Voice and Video Calling feature.

________________________________________________________________

For Xcode 12 and above:

platform :ios, '11.0'
use_frameworks!

target 'YourApp' do
     pod 'CometChatPro', '2.4.1'
     pod 'CometChatCalls', '2.1.0'
end
________________________________________________________________

And then install the CometChatPro framework through CocoaPods.

pod install

If you're facing any issues while installing pods then use below command.

pod install --repo-update

2. Configure CometChat inside your app

i. Initialize CometChat 🌟

The init() method initializes the settings required for CometChat. We suggest calling the init() method on app startup, preferably in the didFinishLaunchingWithOptions() method of the Application class.

import CometChatPro

class AppDelegate: UIResponder, UIApplicationDelegate{

   var window: UIWindow?
   let appId: String = "ENTER APP ID"
   let region: String = "ENTER REGION CODE"
    
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

  let mySettings = AppSettings.AppSettingsBuilder().subscribePresenceForAllUsers().setRegion(region: region).build()
  CometChat(appId: appId ,appSettings: mySettings,onSuccess: { (isSuccess) in
  
                print("CometChat Pro SDK intialise successfully.")

        }) { (error) in
            print("CometChat Pro SDK failed intialise with error: \(error.errorDescription)")
        }
        return true
    }
}

Note : Make sure you replace the APP_ID with your CometChat appId and region with your app region in the above code.


ii.Create User 👤

Once initialisation is successful, you will need to create a user. To create users on the fly, you can use the createUser() method. This method takes an User object and the Auth Key as input parameters and returns the created User object if the request is successful.

let newUser : User = User(uid: "user1", name: "Kevin") // Replace with your uid and the name for the user to be created.
let authKey = "authKey" // Replace with your Auth Key.
CometChat.createUser(user: newUser, apiKey: authKey, onSuccess: { (User) in
      print("User created successfully. \(User.stringValue())")
  }) { (error) in
     print("The error is \(String(describing: error?.description))")
}

iii.Log in your User 👤

The login() method returns the User object containing all the information of the logged-in user.

let uid    = "SUPERHERO1"
let authKey = "ENTER AUTH KEY"

CometChat.login(UID: uid, apiKey: authKey, onSuccess: { (user) in

  print("Login successful: " + user.stringValue())

}) { (error) in

  print("Login failed with error: " + error.errorDescription);

}

Note :

  • Make sure you replace the authKey with your CometChat Auth Key in the above code.

  • We have setup 5 users for testing having UIDs: SUPERHERO1, SUPERHERO2, SUPERHERO3,SUPERHERO4 and SUPERHERO5.


Checkout our iOS UI Kit

Visit our iOS Chat UI Kit repo to integrate it inside your app.


Checkout our sample apps

Swift:

Visit our Swift sample app repo to run the swift sample app.

Objective C:

Visit our Objective-C sample app repo to run the objective-c sample app.


Troubleshooting


Contributors

Thanks to the following people who have contributed to this project:

@pushpsenairekar2911 👨‍💻
@ghanshyammansata 👨‍💻
@jeetkapadia 👨‍💻
@NishantTiwarins 👨‍💻


Contact 📫

Contact us via real time support present in CometChat Dashboard.


License

This project uses the following license.