A singleton. This is how you interact with the Kustomer SDK.

## Public vars

### chatProvider

Alias for [ChatProvider.shared](🔗). This provider class is used to interact with all chat related functionality. See [ChatProvider](🔗).



### pushProvider

Alias for [PushProvider.shared](🔗).



### shared

Shared, thread-safe, singleton



Every method and property of `KustomerClient.shared` is also available on the Kustomer object. Both are thread-safe singletons.



### status

The status of the KustomerClient



### bundle

Bundle containing SDK resources



### sdkVersion

Version of the Kustomer SDK



### pushKeysPresentAndPushEnabled



### getSdkVersion(file:line:function:)

Version of the Kustomer SDK



### sdkVersionBuild



### changeActiveAssistant(ActiveAssistantOptions)

Change the ID of the chat assistant used when the user clicks ‘New conversation’.



Overrides the default chat assistant from your Kustomer app Chat settings.

The default chat assistant applies to new conversations created

  • Via buttons in the UI

  • Via use of openNewConversation(initialMessages:afterCreateConversation:animated)

Do not use a chat assistant:



Use the default chat assistant from your Kustomer website settings, if any:



Use the chat assistant with a specific `id`



**Example**

How to change the chat assistant to a new value, and how to put it back to your organization default



Later, to go back to the assistant ID from your Kustomer web settings:



### getActiveAssistantID()

Gets the id, if any, of the chat assistant that will be used next time a new conversation is started.

changeActiveAssistant(ActiveAssistantOptions) changes this value.



### changeBrand(brandId: completion)



Changes brand.

If `brandId` is `nil`, uses the default brand. If the UI is visible, closes the UI and re-opens it with the new brand.

If the `brandId` is invalid, returns an error.

### changeBusinessSchedule(scheduleId: completion)



Changes the business schedule ID. If the UI is visible, it will be updated.

If the schedule ID is invalid, returns an error.

### options

The options used to configure the SDK. `KustomerOptions` for Kustomer. Once passed to `configure`, they can’t be changed. Never `nil`.



### orgId

The organization ID. Derived from your api key.



### orgName

Your organization’s name



### keychain

A separate iOS keychain for the Kustomer SDK inside your app.



### useCombinedInterface



## Initialization

### configure(apiKey:options:launchOptions)

Configures the Kustomer SDK.



Configures the Kustomer SDK. See [Configuration](🔗).

Must be placed in your AppDelegate's `application(_:didFinishLaunchingWithOptions:)`.

`apiKey`: An API key, with `org.tracking` permissions. `completion`': An optional callback. Used to detect low disk space.

## Dynamic properties

Dynamic properties are dependent on the user

### isChatAvailable(_:)

Alias for [`isChatAvailable()`](🔗).



## UI

### show()

Shows the Knowledge Base in the default view. Alias for `Kustomer.show(.default)`.



### show(preferredView:KustomerDisplayMode)



Shows the Kustomer chat UI. The Kustomer chat UI lets the Customer view their chat history, start a new chat, and browse the knowledge base.

Open the UI using the widget settings from the Kustomer admin website:



Open the UI to a new conversation, using the chat settings from your Kustomer admin website:

  • Works the same as the large blue "New conversation" button in the UI. For example, if "restrict to single open chat" is turned on, and the customer has an open chat, `Kustomer.show(preferredView: .newChat)` will open the existing open chat.



Open the UI to the currently active chat, or creates a new chat if there isn't one:

  • If the customer has an existing open chat, opens it.

  • If not, creates a new conversation and opens it



Open the UI to the chat history screen. Uses the widget settings from the Kustomer admin website to decide if a tab bar should be shown:



Open the UI to the knowledge base screen:

  • Use the widget settings from the Kustomer admin settings to decide if a tab bar should be shown.



Hide the bottom tab bar and opens the UI to the chat history screen:



Hide the bottom tab bar and opens the UI to the knowledge base screen:



### openConversation(id:animated:completion)

Opens an existing conversation.



Open a conversation with the specified ID:



To hide the animation from the chat history screen to the conversation screen, use the `animated` parameter:



Use the optional `completion` block to handle errors and invalid conversation IDs, and to get info about the opened conversation



If the `id` is invalid, the user interface will not be shown.

_Deprecated_ Use startNewConversation

### openNewConversation(initialMessages:afterCreateConversation:animated)

### startNewConversation(initialMessage:presentingVC:afterCreateConversation:animated:)



Opens a new conversation.



💡If you have a default chat assistant enabled, the new conversation will use this default assistant.

To skip the animation from the chat history screen to the conversation screen, use the `animated` parameter:



To pre-populate the chat with an outgoing or incoming text message, add an `initialMessage` parameter:



💡If you have a default chat assistant, initialMessages from `.agent` are ignored

To access the conversation after the customer has replied, use the `afterCreateConversation` parameter. `afterCreateConversation` runs only after the customer sends their first message.



### openChatAssistant(id:completion:afterFirstMessage:)



Starts a new chat with our bot using the passed chat assistant ID.

`id`: The ID of the desired chat assistant `startDialog`: Any opening dialog you wish to append to the chat assistant `presentingVC`: A reference to the view controller that is presenting the chat interface, if nil the Kustomer SDK will attempt to derive it `completion`: If you were able to start chatting with this assistant, success, otherwise an error `afterFirstMessage`: Runs after the first customer-submitted response is processed fully. `initialMessages`: The initial messages from the customer `animated`: Whether or not to animate the presentation. Defaults to 'true'

### showKbArticle(id:)

Opens the knowledge base screen and tries to show an article with the given `id`.



If the `id` is invalid, the UI shows an error message.

### showKbCategory(id:)

Opens the knowledge base screen and loads a specific category with the given `id`.



If the `id` is invalid, the UI shows an error message.

### printLocalizationKeys()



Prints all localized keys available in SDK. Uses the same format as a .strings file. See [Localization](🔗).

### close()

Closes the chat UI.



### close()

Closes the Kustomer UI if it's open. The `completion` block is called after the `KustomerOptions.onDismiss` block.



### isVisible()

Check if your chat UI is currently visible (open or closed).



## Log in and log out

Logging in and out

### logIn



Securely identify a customer w/ the passed JWT. Loads all their chat histories in the background, as network conditions permit.

  • If there are chats already started, links them to this customer.

  • If the customer has any chat history from other devices, loads that history onto this device.

  • May trigger merges and moves of customers and conversations



### logOut



Logs out the customer. Clears the customer's access to any existing chats from the device. If you’re using push, deregisters them from the Kustomer push service.

  • Can fail if you’re using push notifications and we’re unable to deregister them from future pushes (e.g. if they try to log out while there is no internet).

  • Can not fail if you’re not using push notifications.

  • Returns immediately if you're not using push notifications

  • Returns immediately if you are using push notifications but the device/user hasn't registered for push



### logOutThenLogIn



Signs out the current customer if there is one. Then logs in as the customer with the JWT passed. Loads all their chat histories in the background, as network conditions permit.

### identifyCurrentCustomer(jwt:_:)



## Push notifications

### didFailToRegisterForRemoteNotifications(error:)

If you’re using our push notifications, place this in your AppDelegate’s `application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error)` method



### didRegisterForRemoteNotifications(deviceToken:)

If you are using push notifications in the KustomerChat call this function in your own AppDelegate, passing the parameters from `func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)`

`application`: Pass the `application` object that is passed to your AppDelegate `deviceToken`: Pass the `deviceToken` object that is passed to your AppDelegate



### deregisterCurrentDeviceForPushNotifications(_:)

Alias for `PushProvider.deregisterCurrentDeviceForPushNotifications(...)`



### requestAuthorizationForPush()

Alias for `PushProvider.requestAuthorizationForPush(...)`



## Reconnect to pub/sub

### reconnect()

Use to reconnect manually.

(Core SDK only - if you’re using our UI you should never call this method)

Tries to reconnect, and you can monitor the progress via events from `KUSConnectionProvider` . Used to manually re-connect after the internet goes away and comes back.

**Note**: In most cases you won’t need to use this.

Use either after calling stop(), or after handling an `onConnectionStatusChange(status:KustomerConnectionStatus)` with a status of .connected (see `KUSConnectionProvider`)



### stop()

Disconnects from pubsub, stops receiving all events.

(Core SDK only - if you’re using our UI you should never call this method)

If you want to go back online, use `reconnect()`



## Start the client

### start(completion:failure:)

Creates the connection to the Kustomer SDK backend.

`completion`: A block that is passed a Result type. If the connection was created successfully this enum will be `.success`, if the connection failed it will be `.failure(error)` and will have error information. There are no automatic retries.



### start()

Alias for `KustomerClient.start(...)` with no callbacks. Use if you don’t care if the client starts or not. The client will auto start whenever the UI is shown, if you’re using the UI.



### start(completion:)

Alias for `KustomerClient.start(...)` with only a completion callback



### start(failure:)

Alias for `KustomerClient.start(...)` with only a failure callback



## Settings and schedules

### unUserNotificationCenterDelegate



If you have Kustomer [Push Notifications](🔗) enabled, set this to your own `UNUserNotificationCenterDelegate` to process remote and/or local notifications that don't come from Kustomer. This ensures that your delegate will not receive any pushes from Kustomer.

If you are not using Kustomer push notifications, you will not need this.

## Wrappers for ChatProvider methods

### getUnreadCount(completion:)



Alias for [getUnreadCount(completion:)](🔗).

### getUnreadCount()



**Deprecated:** Use [`getUnreadCount(completion:)`](🔗) instead.



Alias for [unreadCount()](🔗).

### getOpenConversationCount(completion:)

The number of open conversations for the current customer.

Alias for [`ChatProvider.getOpenConversationCount(completion:)`](🔗).



### openConversationCount()



**Deprecated:** Use [`getOpenConversationCount(completion:)`](🔗) instead.

The number of open conversations for the current customer. Returns immediately. If there is no current customer, returns `0`.

Alias for [`ChatProvider.openConversationCount(...)`](🔗).



## Reset

### removeAllSessionsAndRelatedData()

Removes all conversations and messages. Keeps the customer logged in. Keeps the SDK connected to pubsub and our platform.