Getting started

The SDK has the following requirements:

  • Minimum iOS version: 10.0
  • Supported Xcode and Swift versions are in the release notes.

To get the Unified SDK working in your app, follow these steps:

  1. Add the Unified SDK dependencies
  2. Initialize the SDK
  3. Identify your users
  4. Start MessagingViewController

The snippets on this page show a simple, light-touch integration using the Support, Chat, and Answer Bot products. If you're not using one of the products, you can omit the lines that refer to that product. Each step ends with a link to further information.

Add the Unified SDK dependencies

Swift Package Manager

  1. Retrieve the URL of the desired product SDK package. Examples: https://github.com/zendesk/answer_bot_sdk_ios for AnswerBot, https://github.com/zendesk/chat_sdk_ios for Chat, or https://github.com/zendesk/support_sdk_ios for Support.

  2. Follow the Apple documentation on how to add the package to your project.

  3. Paste the URL from step 1 into the Choose repository package search bar.

  4. Use version based Package Requirements, and set the value to the latest version of the SDK.

For other integration methods, see Adding the Unified SDK.

Initialize the SDK

First, import the necessary dependencies:

Swift

import ZendeskCoreSDKimport SupportProvidersSDKimport AnswerBotProvidersSDKimport ChatProvidersSDK

Objective-C

#import <ZendeskCoreSDK/ZendeskCoreSDK.h>#import <SupportProvidersSDK/SupportProvidersSDK.h>#import <AnswerBotProvidersSDK/AnswerBotProvidersSDK.h>#import <ChatProvidersSDK/ChatProvidersSDK.h>

Second, paste the following initialization code into the application method with the didFinishLaunchingWithOptions argument.

Swift

Zendesk.initialize(appId: <#appId#>, clientId: <#clientId#>, zendeskUrl: <#url#>)Support.initialize(withZendesk: Zendesk.instance)AnswerBot.initialize(withZendesk: Zendesk.instance, support: Support.instance!)Chat.initialize(accountKey: <#accountKey#>)

Objective-C

[ZDKZendesk initializeWithAppId: <#appId#>    clientId: <#clientId#>    zendeskUrl: <#url#>];[ZDKSupport initializeWithZendesk: [ZDKZendesk instance]];[ZDKAnswerBot initializeWithZendesk:[ZDKZendesk instance] support:[ZDKSupport instance]];[ZDKChat initializeWithAccountKey: <#accountKey#>, queue: dispatch_get_main_queue()];

For more details, see Initializing the SDKs.

Identify your users

Swift

let identity = Identity.createAnonymous(name: <#John Bob#>, email: <#[email protected]#>)Zendesk.instance?.setIdentity(identity)

Objective-C

id<ZDKObjCIdentity> userIdentity = [[ZDKObjCAnonymous alloc] initWithName:<#John Bob#>        email:<#[email protected]#>];[[ZDKZendesk instance] setIdentity:userIdentity];

For more details, see Identify your users.

Build the conversation screen

You specify one or more engine instances to build the conversation view controller. For details, see Running the Answer Bot engine and Running the Support engine.

It's recommended to embed the view controller in a UINavigationController if you are presenting modally. See Presenting the screen in the Unified SDK docs.

Important: The AnswerBotEngine should be placed first in the list of engines. This is important, as the Messaging instance will start the first engine in the list, and will treat any subsequent engines as potential contact options. Answer Bot can hand over to Support and Chat, but no other engine can hand over to Answer Bot.

Swift

func buildUI() throws -> UIViewController {    let messagingConfiguration = MessagingConfiguration()    let answerBotEngine = try AnswerBotEngine.engine()    let supportEngine = try SupportEngine.engine()    let chatEngine = try ChatEngine.engine()
    return try Messaging.instance.buildUI(engines: [answerBotEngine, supportEngine, chatEngine],                                          configs: [messagingConfiguration])}

Objective-C

- (UIViewController *) buildUI {    ZDKMessagingConfiguration *messagingConfiguration = [ZDKMessagingConfiguration new];    NSError *error = nil;    NSArray *engines = @[        (id <ZDKEngine>) [ZDKAnswerBotEngine engineAndReturnError:&error],        (id <ZDKEngine>) [ZDKSupportEngine engineAndReturnError:&error],        (id <ZDKEngine>) [ZDKChatEngine engineAndReturnError:&error]    ];
    return [[ZDKMessaging instance] buildUIWithEngines:engines                                               configs:@[messagingConfiguration]                                                 error:&error];}

Presenting the screen

Use your preferred presentation style (push, modal) to present the view controller. You must embed the viewController in a UINavigationController if presenting modally. You can then add a button to help the user to dismiss the view controller.

private func pushViewController() throws {    let viewController = try buildUI()    self.navigationController?.pushViewController(viewController, animated: true)}
private func presentModally() throws {    let viewController = try buildUI()
    let button = UIBarButtonItem(title: "Close", style: .plain, target: self, action: #selector(dismiss))    viewController.navigationItem.leftBarButtonItem = button
    let chatController = UINavigationController(rootViewController: viewController)    present(chatController, animated: true)}
@objc private func dismiss() {    self.navigationController?.dismiss(animated: true, completion: nil)}

Objective-C

- (void) pushViewController {    UIViewController *viewController = [self buildUI];    [self.navigationController pushViewController:viewController animated:YES];}
- (void) presentModally {    UIViewController *viewController = [self buildUI];    viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @"Close"                                                                                       style: UIBarButtonItemStylePlain                                                                                      target: self                                                                                      action: @selector(dismiss)];
    UINavigationController *chatController = [[UINavigationController alloc] initWithRootViewController: viewController];    [self.navigationController presentViewController:chatController animated:YES completion:nil];}
- (void) dismiss {    [self.navigationController dismissViewControllerAnimated:YES completion:nil];}