开始

Prerequisites

Before starting the integration of the Zendesk SDK, please ensure that the following prerequisites are fulfilled.

Ensure you meet the minimum supported iOS version

The minimum operating system version required for the Zendesk SDK is iOS 11.

Obtain a channel key from Zendesk's Admin Center

Before you initialize your SDK, you'll need to obtain a channel key. The channel key is a unique identifier that the SDK requires to initialize correctly. You can obtain it from the Zendesk Admin Center. For instructions, seeWorking with messaging in the Zendesk SDKs for Android and iOS. If you're not a Zendesk admin on your account, ask one to get it for you.

Add the SDK dependencies

You can add the iOS SDK to your project using one of the following methods:

SeeRelease Notesfor the latest available versions.

Swift Package Manager

Swift Package Manager is a dependency manager for managing and distributing Swift code. It's integrated with the Swift build system. As of Xcode 11, you can use it inside Xcode.

  1. In Xcode, selectFile>Swift Packages>Add Package Dependency.

  2. Add the repositoryhttps://github.com/zendesk/sdk_messaging_ios/and follow Xcode's instructions to add ZendeskMessagingSDK as a dependency. Swift Package Manager will resolve any required dependencies and download them as needed.

CocoaPods

CocoaPods is a dependency manager that lets you add third-party frameworks and libraries to projects. For installation instructions, seeInstall CocoaPods.

  1. In your Podfile, add the following:

                   
    pod'ZendeskSDKMessaging'
  2. Run thepod installcommand.

Carthage

Carthage is a dependency manager for iOS apps. For installation and usage instructions, seeInstalling Carthagein the Carthage readme on Github.

  1. Add the following dependency to your Cartfile.

                   
    github"zendesk/sdk_messaging_ios"
  2. Run迦太基更新——使用-xcframeworks.

    Carthage will check out and download all necessary dependencies to the Carthage/Checkouts directory in your project and place the binaries at Carthage/Build.

  3. Your targetsFRAMEWORK_SEARCH_PATHSshould be updated to point to Carthage/Build.

  4. On your targets General tab, drag each of the downloaded frameworks to theFrameworks, Libraries and Embedded Contentsection and embed the frameworks by selecting the嵌入&符号option.

Manual

  1. Download the following repositories:

    Each repository contains a.xcframeworkfile that you import into your project.

  2. In Xcode, select your project in Project navigator:

  3. In Finder, navigate to where you extracted each of the SDKs.

  4. Ensure aFrameworksdirectory exists in the top level of your project directory. Create this directory if it doesn't exist.

  5. Copy the following items into theFrameworksfolder in your project:

    • ZendeskSDKMessaging.xcframework
    • ZendeskSDK.xcframework
    • ZendeskSDKConversationKit.xcframework
    • ZendeskSDKUIComponents.xcframework
    • ZendeskSDKCoreUtilities.xcframework
    • ZendeskSDKFayeClient.xcframework
    • ZendeskSDKStorage.xcframework
    • ZendeskSDKHTTPClient.xcframework
    • ZendeskSDKLogger.xcframework
    • ZendeskSDKSocketClient.xcframework
  6. Drag the frameworks into theFrameworks, Libraries and Embedded Contentsection of your project and embed the frameworks by selecting嵌入&符号option.

  7. InBuild Settings, set theCLANG_ENABLE_MODULESfield toYES.

Obtain the channel key

Before you initialize your SDK, you'll need to obtain a channel key. The channel key is a unique identifier that the SDK requires to initialize correctly. You can obtain it from the Zendesk Admin Center. For instructions, seeWorking with messaging in the Zendesk SDKs for Android and iOS. If you're not a Zendesk admin on your account, ask one to get it for you.

Initialize the SDK

  1. Add the following import to your project:

    Swift

                   
    import ZendeskSDKMessagingimport ZendeskSDK

    Objective-c

                   
    #import<ZendeskSDKMessaging/ZendeskSDKMessaging.h>#import<ZendeskSDK/ZendeskSDK.h>
  2. CallZendesk.initialize(withChannelKey: ,messagingFactory: ,completionHandler:).

    If successful, an instance of messaging is returned. You don't have to keep a reference to the returned instance because you can access it anytime by usingZendesk.instance.

    Examples:

    Swift

                   
    Zendesk.initialize(withChannelKey: "channel_key",messagingFactory: DefaultMessagingFactory()) { result inif case let .failure(error) = result {print("Messaging did not initialize.\nError: \(error.localizedDescription)")}}

    Objective-C

                   
    [Zendesk initializeWithChannelKey:@""messagingFactory:[[ZDKDefaultMessagingFactory alloc]init]completionHandler:^(亚博*_Nullable zendesk,NSError*_Nullable error){if(error!=nil){NSLog(@"Zendesk did not initialize.\nError: %@",error.localizedDescription);}}];

Show the conversation

  1. Call themessagingViewController()方法作为消息的一部分返回的引用during initialization.

    Swift

                   
    guard let viewController = Zendesk.instance?.messaging?.messagingViewController() else { return }self.navigationController?.show(viewController, sender: self)

    Objective-C

                   
    UIViewController*viewController=[亚博.instance.messaging messagingViewController];if(viewController!=NULL){[self.navigationController showViewController:viewController sender:self];}

Demo Apps

We provide our users multiple demo apps to showcase our SDK's functionalities.

Each app showcases one specific feature, including a basic implementation, JWT authentication, and more. The README file details how to configure and run each app.

You can find them in ourZendesk SDK Demo apps github.

Next Steps

If you have completed the steps above, you are now in good shape to explore the SDK and understand how messaging will work for your business and your end users.

Push Notifications

To ensure a good end-user experience, we also recommend setting up push notifications to work correctly with your app. The steps required to set it up are outlined inPush notifications.

Unread Messages

When the user receives a new message, an event is triggered with the updated total number of unread messages. To subscribe to this event, add an event observer to your Zendesk SDK instance. SeeEventsfor the necessary steps to observe unread messages.

In addition, you can retrieve the current total number of unread messages by callinggetUnreadMessageCount()on Messaging on your Zendesk SDK instance.

Swift

             
Zendesk.instance?.messaging?.getUnreadMessageCount()

Objective-C

             
// Get the instance of messagingZendesk *instance = [Zendesk instance];// Get the unread countNSNumber *unreadCount = @(instance.messaging.getUnreadMessageCount);

Property List Keys

Include the following plist entries to your app to support uploading images or videos taken directly from the camera:

  • NSCameraUsageDescription- allows access to the device’s camera for images and videos.
  • NSMicrophoneUsageDescription- allows access to the device’s microphone for use when capturing videos with the camera.
  • NSPhotoLibraryUsageDescription- allows read and write access in photo library (iOS14+).
  • NSPhotoLibraryAddUsageDescription- allows write access in photo library (below iOS14).
Note
  • Below iOS 14, theNSPhotoLibraryAddUsageDescriptionkey is mandatory, to have the share button displayed and save an image to the photo library.
  • Between iOS 14 and iOS 15 theNSPhotoLibraryUsageDescriptionkey is mandatory, to have the share button displayed and save an image to the photo library.
  • From iOS 15, the share button is always present, however the option to share in the photo library is not present if theNSPhotoLibraryUsageDescriptionkey is missing.

Advanced Integration

To explore more advanced integration options, seeAdvanced integration.

Troubleshooting

We recommend tracking the cause of any initialization failures in your crash reporting dashboard. This will help in troubleshooting your integration once deployed in production.

If you have any difficulty getting starting, or wish to see more detailed information from the SDK, you can enable logging. This can be set in yourAppDelegateinapplication(didFinishLaunchingWithOptions).

Swift

             
import ZendeskSDKLoggerLogger.enabled = trueLogger.level = .default// Possible levels:// .default// .info// .debug// .error// .fault

Objective-C

             
#import<ZendeskSDKLogger/ZendeskSDKLogger.h>ZDKLogger.enabled=YES;ZDKLogger.level=ZDKLogLevelDefault;// Possible levels:// ZDKLogLevelDefault// ZDKLogLevelInfo// ZDKLogLevelDebug// ZDKLogLevelError// ZDKLogLevelFault

Log Levels

Default: A default level which is a general logging level. It's better to be specific by using other log levels.

Info: Contains information that may be helpful, but not essential, while troubleshooting problems.

Debug: Contains information useful during development while actively debugging.

Error: Contains information about errors and failures.

Fault: Contains information about serious problems.