AI Integration Quick Reference
AI Integration Quick Reference
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
CometChatSwiftUIorCometChatUIKitproduct added fromhttps://github.com/cometchat/cometchat-uikit-ios.git, from6.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.- SwiftUI
- UIKit
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
initialize
still succeeds. See Calling Integration.
Authentication
CheckloggedInUser first: the SDK keeps the session across launches, and logging in again is
wasted work.
Login using Auth Key
Login using Auth Token
Production apps create a user’s auth token on their server and log in with it:CometChatError with the SDK’s code and message.
Logout
Create User
The Kit has no create-user call. Create users from your server with the REST API, or with the SDK’sCometChat.createUser during
development.
Date Formatting
There is no app-wide date formatter. Each component that shows dates takes aCometChatDateTimeFormatter — 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
- SwiftUI
- UIKit
Media Message
- SwiftUI
- UIKit
Custom Message
A custom message is sent with its push notification turned on.- SwiftUI
- UIKit
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.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