Skip to main content
Quick Reference for AI Agents & Developers
  • Class: CometChatUIKit
  • Import: import CometChatUIKitSwift
  • Init: CometChatUIKit.init(uiKitSettings:onSuccess:onError:)
  • Login: CometChatUIKit.login(uid:onSuccess:onError:) or CometChatUIKit.login(authToken:onSuccess:onError:)
  • Logout: CometChatUIKit.logout(user:result:)
  • Create user: CometChatUIKit.createUser(user:onSuccess:onError:)
  • Send message: CometChatUIKit.sendTextMessage(message:onSuccess:onError:), sendMediaMessage, sendCustomMessage
  • Related: Getting Started · Events · SDK Overview

Overview

The UI Kit’s core function is to extend the CometChat SDK, translating raw data and functionality into visually appealing, easy-to-use UI components. To effectively manage and synchronize UI elements and data across all components, the UI Kit uses internal events. These events enable real-time change tracking and ensure the UI reflects the most current state of data. The CometChat UI Kit encapsulates critical CometChat SDK methods within its wrapper to efficiently manage internal eventing. This abstraction layer simplifies interaction with the underlying SDK, making it more developer-friendly.

Methods

Access all public methods exposed by the CometChat UI Kit through the CometChatUIKit class.

Init

You must invoke this method before using any other UI Kit methods. This initialization ensures the UI Kit and Chat SDK function correctly in your application. Best practice is to make this one of the first lines of code executed in your application’s lifecycle.
Replace APP_ID, REGION, and AUTH_KEY with your CometChat App ID, Region, and Auth Key. The Auth Key is an optional property of the UIKitSettings class, intended primarily for proof-of-concept (POC) development or early stages of application development. For production, use Auth Token instead.

UIKitSettings Properties

Example


Login using Auth Key

Only the UID of a user is needed to log in. This simple authentication procedure is useful for POC or development phases. For production apps, use AuthToken instead.

Login using Auth Token

This advanced authentication procedure does not use the Auth Key directly in your client code, ensuring better security.
  1. Create a User via the CometChat API when the user signs up in your app.
  2. Create an Auth Token via the CometChat API for the new user and save the token in your database.
  3. Load the Auth Token in your client and pass it to the login(authToken:) method.

Logout

The CometChat UI Kit and Chat SDK handle the session of the logged-in user within the framework. Before a new user logs in, clean this data to avoid potential conflicts or unexpected behavior by invoking the .logout(user:) function.

Create User

Dynamically create users on CometChat using the .create(user:) function. This is useful when users are registered or authenticated by your system and need to be created on CometChat.

Base Message

Text Message

To send a text message to a single user or a group, use the sendTextMessage() function. This function requires a TextMessage object containing the necessary information for delivering the message.
CometChatUIKit.sendTextMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendTextMessage() only sends the message without updating these UI Kit components.

Media Message

To send a media message to a single user or a group, use the sendMediaMessage() function. This function requires a MediaMessage object containing the necessary information for delivering the message.
CometChatUIKit.sendMediaMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendMediaMessage() only sends the message without updating these UI Kit components.

Custom Message

To send a custom message to a single user or a group, use the sendCustomMessage() function. This function requires a CustomMessage object containing the necessary information for delivering the message.
CometChatUIKit.sendCustomMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendCustomMessage() only sends the message without updating these UI Kit components.

Interactive Message

Form Message

To send a Form message to a single user or a group, use the sendFormMessage() function. This function requires a FormMessage object containing the necessary information to create a form bubble for that message.

Card Message

To send a Card message to a single user or a group, use the sendCardMessage() function. This function requires a CardMessage object containing the necessary information to create a card bubble for the message.

Scheduler Message

To send a Scheduler message to a single user or a group, use the sendSchedulerMessage() function. This function requires a SchedulerMessage object containing the necessary information to create a scheduler bubble for the message.


Next Steps

Events

Listen to UI Kit component events

Getting Started

Set up the iOS UI Kit from scratch

Components Overview

Explore all available UI components

SDK Overview

Explore the underlying CometChat SDK