iOS Quick Start Guide

Get up and running quickly with the Agentforce Mobile SDK for iOS using these instructions.

Before You Begin 

Ensure you have:

  • A Salesforce org with Agentforce enabled
  • An agent configured in your org (Employee Agent or Service Agent)
  • The required values from your Salesforce org depending on agent type

For detailed setup instructions, see Before You Begin.

For Service Agent 

You need these values from your Salesforce org:

  • Service API URL: Setup > Embedded Service Deployments > your deployment > Settings
  • Organization ID: Setup > Company Information
  • ES Developer Name: Setup > Embedded Service Deployments > Developer Name

For Employee Agent 

You need these values from your Salesforce org:

  • Agent ID: From the Agent Details page URL (the 18-character ID at the end)
  • User ID: From the user profile. See Find the Salesforce ID for a User.
  • My Domain URL: Setup > My Domain > Current My Domain URL

1. Install Dependencies 

Add the Agentforce SDK to your project using CocoaPods.

Install Dependencies
1# Add to the top of your podfile
2source 'https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Specs.git'
3source 'https://github.com/livekit/podspecs.git'
4source 'https://cdn.cocoapods.org/'
5
6# Add to your target
7target 'MyApp' do
8  pod 'AgentforceSDK'
9  pod 'Messaging-InApp-Core', '> 1.10.0'
10  pod 'LiveKitClient' # Required to ensure Cocoapods looks in the correct source location
11end
12
13# Add to the bottom of your podfile where you set up your post installer
14post_install do |installer|
15  installer.pods_project.targets.each do |target|
16    target.build_configurations.each do |config|
17      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
18    end
19  end
20end

To learn more, see Install the iOS SDK.

2. Add Required Permissions 

See iOS Requirements.

3. Implement Credential Provider 

To use the SDK, be sure to import the Agentforce SDK package.

Agentforce SDK Import
1import AgentforceSDK

Create a credential provider using one of the supported authentication methods.

Sample OAuth Implementation
1class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
2    public func getAuthCredentials() -> AgentforceAuthCredentials {
3        return .OAuth(
4            authToken: "YOUR_AUTH_TOKEN",
5            orgId: "YOUR_ORG_ID",
6            userId: "YOUR_USER_ID"
7        )
8    }
9}
Sample JWT Implementation
1class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
2    public func getAuthCredentials() -> AgentforceAuthCredentials {
3        return .OrgJWT(orgJWT: "YOUR_ORG_JWT")
4    }
5}
Sample Guest User Implementation
1class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
2    public func getAuthCredentials() -> AgentforceAuthCredentials {
3        return .Guest("")
4    }
5}

To learn more, see Integrate Agentforce SDK.

4. Configure Chat 

Configure your chat object for Employee agent or Service agent.

For guidance on gathering information for the agent configuration object, see Agent Type Setup in Before You Begin.

Tip

Employee Agent Configuration
1let user = User(userId: "YOUR_USER_ID", org: Org(id: "YOUR_ORG_ID"), displayName: "User Display Name")
2
3// Configure an Employee agent
4let config = EmployeeAgentConfiguration(
5    user: user,
6    forceConfigEndpoint: "https://your-domain.my.salesforce.com"
7)
8
9// Create client
10let client = AgentforceClient(
11   credentialProvider: credentialProvider,
12   mode: .employeeAgent(config)
13)
Service Agent Configuration
1// Set up Service UI settings
2let serviceUISettings = ServiceUISettings(
3    downloadTranscript: false, // Whether to show the download transcript option
4    endConversation: true      // Whether to show the end conversation option
5)
6
7// Configure a Service agent
8let config = ServiceAgentConfiguration(
9    esDeveloperName: "YOUR_CHAT_DEVELOPER_NAME",
10    organizationId: "YOUR_ORG_ID",
11    serviceApiURL: "https://your-service-api-url.com",
12    serviceUISettings: serviceUISettings
13)
14
15// Create client
16let serviceClient = AgentforceClient(
17    credentialProvider: credentialProvider,
18    mode: .serviceAgent(config)
19)

To learn more, see Integrate Agentforce SDK.

5. Start and Present Chat 

Start the chat conversation and present the chat UI.

Employee Agent Start Chat
1let employeeConversation = agentforceClient.startAgentforceConversation(
2    forAgentId: "YOUR_AGENT_ID"
3)
4let chatView = try client.createAgentforceChatView(
5    conversation: employeeConversation,
6    delegate: nil,
7    onContainerClose: { /* handle close */ }
8)
Service Agent Start Chat
1let serviceConversation = agentforceClient.startAgentforceConversation(
2    forESDeveloperName: "YOUR_CHAT_DEVELOPER_NAME"
3)
4let chatView = try client.createAgentforceChatView(
5    conversation: serviceConversation,
6    delegate: nil,
7    onContainerClose: { /* handle close */ }
8)

To learn more, see Integrate Agentforce SDK. For guidance on getting values for the createAgentforceChatView method, see Agent Type Setup.

Next Steps