Skip to main content
CometChatSession is the Kit’s front door: an async wrapper over the Chat SDK’s set-up calls with the Kit’s defaults built in. Every call is @MainActor.

When to use this

  • Initialise the Kit once at launch, then log a user in.
  • Send a message from your own code and have the Kit’s lists show it.
  • Check whether a server-side feature is on before showing your own UI for it.

Prerequisites

  • The CometChatSwiftUI or CometChatUIKit product added from https://github.com/cometchat/cometchat-uikit-ios.git, from 6.0.0-beta.1 — see Getting Started.
  • Your App ID, Region and, for development, Auth Key from the CometChat dashboard.
CometChatSession lives in CometChatCore, which both toolkits re-export: import CometChatSwiftUI or import CometChatUIKit is enough.

API reference

Initialization

Initialize

Call it once, before any other Kit call — at launch, before the first screen that shows chat.
ChatApp.swift
initialize also turns the SDK’s socket on, so real-time updates arrive. There is no auth key, AI-feature list, extension list or date-formatter setting at initialisation: the auth key goes to login, and date formats are set per component.
The overload initialize(appID:region:subscribePresenceForAllUsers:enableThreadSubscription:) is deprecated. Thread subscription is on by default, so true does nothing; false is the only app-wide opt-out. Prefer hiding the surfaces per screen.

Calling

The Calls SDK is set up after the Chat SDK; if it fails, calling stays off and initialize still succeeds. See Calling Integration.

Authentication

Check loggedInUser first: the SDK keeps the session across launches, and logging in again is wasted work.

Login using Auth Key

The auth key is a shared secret: anyone who unpacks your app can log in as any user. Use it for development only.

Login using Auth Token

Production apps create a user’s auth token on their server and log in with it:
Both logins connect the socket and, with calling on, log the Calls SDK in. Both throw a CometChatError with the SDK’s code and message.

Logout

With calling on, push tokens are unregistered and the Calls SDK logs out first, while the session still authenticates those requests.

Create User

The Kit has no create-user call. Create users from your server with the REST API, or with the SDK’s CometChat.createUser during development.

Date Formatting

There is no app-wide date formatter. Each component that shows dates takes a CometChatDateTimeFormatter — dateTimeFormatter: in SwiftUI, dateTimeFormatter in UIKit — and several UIKit components also have a static default. Implement only the buckets you want; nil keeps the Kit’s text:

Base Message

Send through the Kit rather than the SDK when the Kit is on screen. The SDK does not echo your own sends, so these announce each one — messageSent with .inProgress, then .success with the server’s message or .error with yours — and the message list and Conversations update.

Text Message

Media Message

Custom Message

A custom message is sent with its push notification turned on.
The sender, the local id (muid) and the sent time are filled in when missing. On failure the message’s metadata holds the error under error, errorCode and errorDetails, and the call throws (or completes with .failure).

Feature Flags

Read the server-side switches the Kit’s own options are gated on:

Logging

The Kit is silent by default. Give it a sink to see what it does — sessions, listeners, pages, error codes. Events never carry message text, names, tokens or credentials, and ids are hashed.
Implement CometChatLogSink to send them to your own diagnostics; receive(_:) can be called from any thread.

Next steps

Getting Started

Install and set up the Kit

Events

What the Kit announces, and what you must

Architecture

How the products are layered

Troubleshooting

Common problems and fixes