Quick Setup: Chat in the Service Chat SDK
To add Chat to your iOS app, create an SCSChatConfiguration object and pass it to the showChat method.
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.
Before running through these steps, be sure you’ve already:
- Set up Service Cloud to work with Chat. To learn more, see Org Setup for Chat in Lightning Experience with a Guided Flow.
- Installed the SDK. To learn more, see Install the Service Chat SDK for iOS.
Once you’ve reviewed these prerequisites, you’re ready to begin.
These steps describe how to set up Chat with the default UI. If you prefer to build your own user interface, see Build Your Own UI with the Chat Core API.
-
Import the SDK. Wherever you intend to use the Chat SDK, be sure to import the ServiceCore framework and the ServiceChat framework.
In Swift:
In Objective-C:
-
Create an
SCSChatConfigurationinstance with information about your LiveAgent pod, your Salesforce org ID, the deployment ID, and the button ID.In Swift:
In Objective-C:
You can get the required parameters for this method from your Salesforce org. See Get Chat Settings from Your Org. If your Salesforce admin hasn’t already set up Chat in Service Cloud or you need more guidance, see Org Setup for Chat in Lightning Experience with a Guided Flow.
-
(Optional) Configure the visitor name, queue display style, whether the user can minimize the chat session, and various other configuration settings.
See Configure a Chat Session for more information.
-
(Optional) Customize the appearance with the configuration object.
You can configure the colors, fonts, and images to your interface with an
SCAppearanceConfigurationinstance. It contains the methodssetColor,setFontDescriptor, andsetImage. You can also configure the strings used throughout the interface. See SDK Customizations with the Service Chat SDK for iOS. -
(Optional) Specify any pre-chat fields.
You can specify both optional and required fields shown to the user before a chat session starts. You can also directly pass data to an agent without requiring any user input. These fields can be mapped directly to fields in a record in your org.
See Show Pre-Chat Fields to User and Create or Update Salesforce Records from a Chat Session for more information.
-
To start a chat session, call the
showChat(with:showPrechat:)method onSCSChatInterface.In Swift:
In Objective-C:
The
showChatmethod must be called on the main UI thread.You can provide an optional completion block to execute code when the session has been fully connected to all services. During a successful session initialization, the SDK calls the completion block at the point that the session is active and the user is waiting for an agent to join. If there is a failure, the SDK calls the completion block with the associated error.
-
Listen for events and handle error conditions.
You can detect when a session ends by implementing the
session(didEnd:)method on theSCSChatSessionDelegatedelegate. Register this delegate using theadd(delegate:)method on yourSCSChatinstance. In particular, we suggest that you handle the.agentreason (for when an agent ends a session) and the.noAgentsAvailablereason (for when there are no agents available). See Listen for State Changes and Events.The SDK doesn’t show an alert when a session fails to start, or when a session ends. It’s your responsibility to listen to events and display an error when appropriate.
These steps embed the chat experience into your app.
To learn about chat timeout limitations on iOS devices, see When does a chat session time out?
To use this example code, create a Single View Application and Install the Service Chat SDK for iOS.
Use the storyboard to add a button to the view. Add a Touch Up Inside action in your UIViewController implementation with the name startChat. In the view controller code:
- Implement the
SCSChatSessionDelegateprotocol so that you can be notified when there are errors or state changes. - Specify
selfas a chat delegate. - Start a chat session in the button action.
- Implement the
session(didEnd:)method and show a dialog when appropriate.
In Swift:
In Objective-C: