AI Integration Quick Reference
AI Integration Quick Reference
login() method.
How It Works
Before You Log In
Create a User
A user must exist in CometChat before they can log in.- During development: Create users from the CometChat Dashboard. Five test users are already available with UIDs
cometchat-uid-1throughcometchat-uid-5. - In production: Call the Create User REST API when a user signs up in your app.
createUser() (development only):
- Swift
- Objective-C
Check for an Existing Session
The SDK persists the logged-in user’s session locally. Before callinglogin(), always check whether a session already exists — this avoids unnecessary login calls and keeps your app responsive.
getLoggedInUser() returns nil, no active session exists and you need to call login().
Login with Auth Key
Auth Key login is the simplest way to get started. Pass a UID and your Auth Key directly from the client.- Swift
- Objective-C
| Parameter | Description |
|---|---|
| UID | The UID of the user to log in |
| authKey | Your CometChat Auth Key |
User object containing the logged-in user’s details.
Login with Auth Token
Auth Token login keeps your Auth Key off the client entirely. Your server generates a token via the REST API and passes it to the client.- Create the user via the REST API when they sign up (first time only).
- Generate an Auth Token on your server and return it to the client.
- Pass the token to
login().
- Swift
- Objective-C
| Parameter | Description |
|---|---|
| authToken | Auth Token generated on your server for the user |
User object containing the logged-in user’s details.
Logout
Calllogout() when your user logs out of your app. This clears the local session.
- Swift
- Objective-C
Next Steps
Send Messages
Send your first text, media, or custom message
User Management
Create, update, and delete users programmatically
Connection Status
Monitor the SDK connection state in real time
Ringing Calls
Implement voice and video calls with ringing