Getting started

The SDK has the following requirements:

  • Minimum iOS version: 11.0
  • Supported Xcode and Swift versions are in therelease 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. Build the conversation screen
  5. Present the screen

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_iosfor AnswerBot,https://github.com/zendesk/chat_sdk_iosfor Chat, orhttps://github.com/zendesk/support_sdk_iosfor Support.

  2. Follow theApple documentationon how to add the package to your project.

  3. Paste the URL from step 1 into theChoose repository packagesearch bar.

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

For other integration methods, seeAdding 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 theapplicationmethod with thedidFinishLaunchingWithOptionsargument.

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, seeInitializing 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:<#johnbob@example.com#>];[[ZDKZendesk instance]setIdentity:userIdentity];

For more details, seeIdentify your users.

Build the conversation screen

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

It's recommended to embed the view controller in a UINavigationController if you are presenting modally. SeePresenting the screenin 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:enginesconfigs:@[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 = buttonlet 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=[selfbuildUI];[self.navigationController pushViewController:viewController animated:YES];}-(void)presentModally{UIViewController*viewController=[selfbuildUI];viewController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"Close"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(dismiss)];UINavigationController*chatController=[[UINavigationController alloc]initWithRootViewController:viewController];[self.navigationController presentViewController:chatController animated:YES completion:nil];}-(void)dismiss{[self.navigationController dismissViewControllerAnimated:YES completion:nil];}

Integrate with SwiftUI

See the documentation hereif you are integrating the SDK in aSwiftUIview hierarchy.

Running dependencies with SPM on Xcode 13.3

Some issues are identified while running Classic SDKs installed with SPM on Xcode 13.3 and later. If this is the case, make sure to uninstall and re-install the latest version of all Classic SDKs dependencies.