Swift Concurrency async/await
The public APIs of the Zendesk SDK support async/await operations. This feature is available only on iOS 13.0.0 and above.
- Initialize the Zendesk SDK and present the messaging view.
Task {do {let zendesk = try await Zendesk.initialize(withChannelKey: Const.channelKey, messagingFactory: DefaultMessagingFactory())if let messagingViewcontroller = zendesk.messaging?.messagingViewController() {// Present the messaging view controller according to your preference// for example:navigationController?.pushViewController(messagingViewcontroller, animated: true)}} catch let error {// Handle any initialization error}}
- Authenticate and unauthenticate a user:
func login() {Task {do {let zendeskUser = try await Zendesk.instance?.loginUser(with: "JWT")} catch let error {// Handle any authentication error}}}func logout() {Task {do {try await Zendesk.instance?.logoutUser()} catch let error {// Handle any authentication error}}}
- Send a page view event that captures a specific user interaction to the PageView endpoint:
// Create a `PageView` objectlet pageView = PageView(pageTitle: pageTitle, url: url)Task {do {try await Zendesk.instance?.sendPageViewEvent(pageView)} catch let error {// Handle any error}}