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.
Important
Listening to State Changes
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.
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:
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.
1import UIKit2import ServiceCore3import ServiceChat45class MyChatSessionDelegateImplementation: NSObject, SCSChatSessionDelegate {67 // TO DO: Register this delegate using8 // ServiceCloud.shared().chatCore.add(delegate: myDelegate)910 /**11 Delegate method to handle state change.12 */13 func session(_ session: SCSChatSession!,14 didTransitionFrom previous: SCSChatSessionState,15 to current: SCSChatSessionState){1617 NSLog("Chat state changed...")1819 switch current {20 case .connecting:21 NSLog("Chat now connecting...")22 case .connected:23 NSLog("Chat connected...")24 // TO DO: Handle other reasons25 default:26 break27}28}2930 /**31 Delegate method for session stop event.32 */33 func session(_ session: SCSChatSession!, didEnd endEvent: SCSChatSessionEndEvent!){3435 var reason = "Unknown"3637 switch endEvent.reason {38 case .agent:39 reason = "The agent has ended the session."40 case .noAgentsAvailable:41 reason = "No agents were available."42 default:43 // TO DO: Handle other reasons44 break45}4647 NSLog("\nChat End Session. Reason: \(reason)")4849 // You can access the session ID from the SCSChatSession object50 let sessionId = session.sessionId51}5253 /**54 Delegate method for error conditions.55 */56 func session(_ session: SCSChatSession!, didError error: Error!, fatal: Bool){57 // TO DO: Handle error condition58 NSLog("Chat error: \(error.localizedDescription)")59}60}