Handling events

You can listen for different events that occur in the SDK API and UI.

Before you start

Before you start, the following information is useful to know:

  • You can hook onto lifecycle events called during the normal operation of UI and API calls.
  • The events don't contain any information. For example, the ZD_HC_ArticleByIdSuccess event, which triggers when you open an article, won't contain any information on the article.
  • You can then use this information to perform other actions in your app. For example, if you know that a support request has been created, you may want to suppress marketing activity.

Listening for events

The Support SDK broadcasts state changes using NSNotificationCenter. To subscribe to an event, add an observer to NSNotificationCenter.

Swift

NotificationCenter.default.addObserver(self, selector: #selector(submitRequestCompleted), name: NSNotification.Name(rawValue: ZDKAPI_RequestSubmissionSuccess), object: nil)

Objective-C

[[NSNotificationCenter defaultCenter] addObserver:self                                         selector:@selector(submitRequestCompleted:)                                             name:ZDKAPI_RequestSubmissionSuccess                                           object:nil];

For more information, see NSNotificationCenter in the Apple developer docs.

Available events

A full list of events is available in the ZendeskSDKConstants.h file in the SDK. The file is located in the ZendeskProviderSDK.framework/Headers folder after installing the SDK.

Event names have the following format:

ZDKAPI_{EventName}

Example from ZendeskSDKConstants.h:

/** * Notification that a request has been successfully submitted. */extern NSString * const ZDKAPI_RequestSubmissionSuccess;

The events in the following sections are only a subset of all available events.

Request submission events

The SDK lets you track the progress of support requests submitted by users.

Event nameDescription
ZDKAPI_RequestSubmissionStartingA request is about to be submitted
ZDKAPI_RequestSubmissionSuccessA request has been successfully submitted
ZDKAPI_RequestSubmissionErrorThere was an error during request submission

Request events

You can attach a listener to ViewRequest and be notified of the following events.

Event nameDescription
ZDKAPI_CommentListStartingThe comment list is about to be retrieved
ZDKAPI_CommentListSuccessThe comment list has been retrieved
ZDKAPI_CommentListErrorThere was an error while retrieving the comment list
ZDKAPI_CommentSubmissionStartingA comment is about to be submitted
ZDKAPI_CommentSubmissionSuccessA comment has been successfully submitted
ZDKAPI_CommentSubmissionErrorThere was an error during comment submission

Request list events

You can attach observers to RequestList and be notified of the following events.

Event nameDescription
ZDKAPI_RequestsStartingThe request list is about to be retrieved
ZDKAPI_RequestsSuccessThe request list was successfully retrieved
ZDKAPI_RequestsErrorThere was an error while retrieving the request list