Skip to main content

Documentation Index

Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt

Use this file to discover all available pages before exploring further.

// Get current status: "connecting" | "connected" | "disconnected"
let status = CometChat.getConnectionStatus?.value

// Listen for connection changes
// Conform to CometChatConnectionDelegate
CometChat.addConnectionListener("LISTENER_ID", self as CometChatConnectionDelegate)

func connecting() { print("Connecting...") }
func connected() { print("Connected") }
func disconnected() { print("Disconnected") }

// Cleanup
CometChat.removeConnectionListener("LISTENER_ID")
The CometChat SDK maintains a WebSocket connection to CometChat servers for real-time events. You can check the current connection state and listen for changes, useful for showing connectivity indicators in your UI or queuing operations while offline. When the connection drops, the SDK automatically attempts to reconnect, cycling through disconnected -> connecting -> connected.

Connection States

ValueCallbackDescription
"connected"connected()SDK has an active connection to CometChat servers
"connecting"connecting()SDK is attempting to establish or re-establish a connection
"disconnected"disconnected()SDK is disconnected due to network issues or other errors

Get Current Status

Use getConnectionStatus to check the current connection state at any time:
var connectionStatus = CometChat.getConnectionStatus?.value

Listen for Connection Changes

Register a CometChatConnectionDelegate to receive real-time connection state updates. We recommend adding this in your AppDelegate and in your app’s first view controller after login.
extension AppDelegate: CometChatConnectionDelegate {

    func connecting() {
        print("connecting")
    }
    
    func connected() {
        print("connected")  
    }
    
    func disconnected() {
        print("disconnected")
    }
}
Always remove connection listeners when they’re no longer needed. Failing to remove listeners can cause memory leaks and duplicate event handling.

Next Steps

WebSocket Management

Manage WebSocket connection behavior

Setup SDK

Install and initialize the CometChat SDK

Authentication

Authenticate users with the CometChat SDK

Overview

Overview of the CometChat iOS SDK