Listen for State Changes and Events

Implement SCSChatSessionDelegate to be notified about state changes made before, during, and after a chat session. This delegate also allows you to listen for error conditions so you can present alerts to the user when applicable.

The legacy chat product is scheduled for retirement on February 14, 2026, and is in maintenance mode until then. During this phase, you can continue to use chat, but we no longer recommend that you implement new chat channels. To avoid service interruptions to your customers, migrate to Messaging for In-App and Web before that date. Messaging offers many of the chat features that you love plus asynchronous conversations that can be picked back up at any time. Learn about chat retirement in Help.

A chat session can be in one of the following states:

Inactive

No active session.

Connecting

A connection with chat servers is being established.

Queued

A connection has been established, and is now in the queue for next available agent.

Connected

Connected with an agent .

Ending

Session is cleaning up the connection at the end of a session.

These states are defined in SCSChatSessionState.

Throughout a session, your application might want to know the current state. You can monitor state changes by implementing SCSChatSessionDelegate. Use the add(delegate:) method on SCSChat to register your delegate. Use the session(didTransitionFrom:to:) method to listen for state changes.

The SDK doesn’t present UI alerts for session termination or error conditions so you’ll need to listen for these events and decide what to show your users. There are two SCSChatSessionDelegate methods for this purpose:

  1. To track session termination, use the session(didEnd:) method. Inspect the reason (SCSChatSessionEndEvent.type) to determine why the session stopped. Use the SCSChatSession object to get the session ID and other session information.
  2. You can track errors with the session(didError:fatal:) method. Compare the error code to SCSChatErrorCode to determine what kind of error occurred.

This sample code does the following: