# 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](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-before-you-begin.md).

### 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](https://help.salesforce.com/s/articleView?id=000381643\&type=1).
- **My Domain URL**: Setup > My Domain > Current My Domain URL

## 1. Install Dependencies

Add the Agentforce SDK to your project using CocoaPods.

```sfdocs-code {"lang":"ruby", "title": "Install Dependencies"}
# 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](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-install.md).

## 2. Add Required Permissions

See [iOS Requirements](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-requirements.md).

## 3. Implement Credential Provider

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

```sfdocs-code {"lang":"swift", "title": "Agentforce SDK Import"}
import AgentforceSDK
```

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

```sfdocs-code {"lang":"swift", "title": "Sample OAuth Implementation"}
class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .OAuth(
            authToken: "YOUR_AUTH_TOKEN",
            orgId: "YOUR_ORG_ID",
            userId: "YOUR_USER_ID"
        )
    }
}
```

```sfdocs-code {"lang":"swift", "title": "Sample JWT Implementation"}
class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .OrgJWT(orgJWT: "YOUR_ORG_JWT")
    }
}
```

```sfdocs-code {"lang":"swift", "title": "Sample Guest User Implementation"}
class MyAppCredentialProvider: AgentforceAuthCredentialProviding {
    public func getAuthCredentials() -> AgentforceAuthCredentials {
        return .Guest(url: "https://your-domain.my.salesforce.com")
    }
}
```

To learn more, see [Integrate Agentforce SDK](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-integration.md).

## 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](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-before-you-begin.md#agent-type) in Before You Begin.
:::

```sfdocs-code {"lang":"swift", "title": "Employee Agent Configuration"}
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)
)
```

```sfdocs-code {"lang":"swift", "title": "Service Agent Configuration"}
// 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](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-integration.md).

## 5. Start and Present Chat

Start the chat conversation and present the chat UI.

```sfdocs-code {"lang":"swift", "title": "Employee Agent Start Chat"}
let employeeConversation = agentforceClient.startAgentforceConversation(
    forAgentId: "YOUR_AGENT_ID"
)
let chatView = try client.createAgentforceChatView(
    conversation: employeeConversation,
    delegate: nil,
    onContainerClose: { /* handle close */ }
)
```

```sfdocs-code {"lang":"swift", "title": "Service Agent Start Chat"}
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](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-integration.md). For guidance on getting values for the `createAgentforceChatView` method, see [Agent Type Setup](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-before-you-begin.md#agent-type).

## Next Steps

- **Customization**: See [Theming](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-branding-theming.md) for visual customization
- **Full Integration**: See [Integration Guide](/docs/ai/agentforce-mobile-sdk/guide/agentforce-mobile-sdk-ios-integration-overview.md) for complete implementation
- **Sample App**: See Kiko's Matcha Shop in the [AgentforceMobileSDK-iOS repository](https://github.com/salesforce/AgentforceMobileSDK-iOS/tree/main/Sample%20Apps/KikosMatchaShop), a SwiftUI app that combines guest authentication, custom theming, a custom view provider, and Agentforce Voice. The sample is provided as a reference implementation and isn't supported as a product.
