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.

# Add to the top of your podfile
source 'https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Specs.git'
source 'https://github.com/livekit/podspecs.git'
source 'https://cdn.cocoapods.org/'

# Add to your target
target 'MyApp' do
  pod 'AgentforceSDK'
  pod 'Messaging-InApp-Core', '> 1.10.0'
  pod 'LiveKitClient' # Required to ensure Cocoapods looks in the correct source location
end

# Add to the bottom of your podfile where you set up your post installer
post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
    end
  end
end

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.

import AgentforceSDK

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

class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .OAuth(
            authToken: "YOUR_AUTH_TOKEN",
            orgId: "YOUR_ORG_ID",
            userId: "YOUR_USER_ID"
        )
    }
}
class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .OrgJWT(orgJWT: "YOUR_ORG_JWT")
    }
}
class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .Guest("")
    }
}

To learn more, see Integrate Agentforce SDK.

4. Configure Chat

Configure your chat object for Employee agent or Service agent.

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

let user = User(userId: "YOUR_USER_ID", org: Org(id: "YOUR_ORG_ID"), displayName: "User Display Name")

// Configure an Employee agent
let config = EmployeeAgentConfiguration(
    user: user,
    forceConfigEndpoint: "https://your-domain.my.salesforce.com"
)

// Create client
let client = AgentforceClient(
   credentialProvider: credentialProvider,
   mode: .employeeAgent(config)
)
// Set up Service UI settings
let serviceUISettings = ServiceUISettings(
    downloadTranscript: false, // Whether to show the download transcript option
    endConversation: true      // Whether to show the end conversation option
)

// Configure a Service agent
let config = ServiceAgentConfiguration(
    esDeveloperName: "YOUR_CHAT_DEVELOPER_NAME",
    organizationId: "YOUR_ORG_ID",
    serviceApiURL: "https://your-service-api-url.com",
    serviceUISettings: serviceUISettings
)

// Create client
let serviceClient = AgentforceClient(
    credentialProvider: credentialProvider,
    mode: .serviceAgent(config)
)

To learn more, see Integrate Agentforce SDK.

5. Start and Present Chat

Start the chat conversation and present the chat UI.

let employeeConversation = agentforceClient.startAgentforceConversation(
    forAgentId: "YOUR_AGENT_ID"
)
let chatView = try client.createAgentforceChatView(
    conversation: employeeConversation,
    delegate: nil,
    onContainerClose: { /* handle close */ }
)
let serviceConversation = agentforceClient.startAgentforceConversation(
    forESDeveloperName: "YOUR_CHAT_DEVELOPER_NAME"
)
let chatView = try client.createAgentforceChatView(
    conversation: serviceConversation,
    delegate: nil,
    onContainerClose: { /* handle close */ }
)

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

Next Steps

  • Customization: See Theming for visual customization
  • Full Integration: See Integration Guide for complete implementation