Listing cases and their details with the Connect SDK on iOS
This tutorial demonstrates how to configure and integrate the Connect SDK features with a new iOS application that was created in the Xcode development environment by using the Swift language. The tutorial explains how to use the Connect SDK Cases API to obtain a list of cases for a user and display the case details.
The tutorial contains the following sections:
Prerequisites
Before you start this tutorial, do the following tasks:
- Read Tutorial: Creating a Hello World iOS app with the Connect SDK, which demonstrates how to set up the Connect SDK in the Xcode environment, initialize it in the application, and use it to authenticate.
- Download the ZIP file, which contains the sample Swift code and other Xcode project files for the iOS app that is described in this tutorial.
You can connect to any Pega® Platform instance to test the sample iOS app. Make sure that it already includes some cases and assignments.
Obtaining a list of cases
You can use the Cases API to obtain a list of cases for the Pega Platform application.
- In the Xcode environment, click
UITableViewController
. > > and create a subclass of - Name the subclass
CasesVC.
This subclass is where all the logic that is related to obtaining a list of cases for a Pega 7 Platform application is placed. It is also linked to a new scene for your application's user interface. This scene should be based on a template or be inherited from another class. - Declare a
cases
property to represent the obtained cases within this new class:var cases = [PMCaseInfo]()
- Create the
getCases()
method for theCasesVC
class. Make a call to thegetAll()
method of thecasesService
Connect SDK object to obtain a list of available cases. This method returns an array of cases denoted by the cases completion block parameter. The returned contents are then referenced by the local cases property that was declared earlier for theCasesVC
class:func getCases() { PegaApi.shared.casesService.getAll { cases, error in if let error = error { self.showAlert(with: error) } else if let cases = cases { self.cases = cases.sorted { $0.lastUpdateTime! > $1.lastUpdateTime! } DispatchQueue.main.async { self.tableView.reloadData() } } } }
- Override the
viewWillAppear()
method for the class and call thegetCases()
method so that thegetCases()
method is called when theCasesVC
view is about to appear. Override important methods inherited fromUITableViewController: tableView(_:numberOfRowsInSection:), tableView(_:cellForRowAt:), tableView(_:didSelectRowAt:), prepare(for segue:sender:)
so that the fetched cases are presented in theCasesVC
table view cells. For a preview of the implementation, see the demo project.List of cases - Cases API
Obtaining case details
After you receive a list of cases, you can add code that obtains the details for a particular case based on its identifier.
- In the Xcode environment, click
UIViewController
. > > and create a subclass of - Name the subclass
CaseDetailsVC
. This subclass is where all the logic that is related to obtaining case details is placed. It is also linked to a separate scene of your application's user interface. This scene should be based on a template or be inherited from the given class. - Declare a
caseID
property, which is where the case identifier is passed from the segue from theCasesVC
class:var caseID: String?
- Add the
getCase()
method to the class where you call thegetCase()
method for thecasesService
Connect SDK object. This method contains one parameter that specifies the identifier of the case for which to obtain details. The identifier was passed from theCasesVC
segue. It returns acaseItem
variable that contains the case details. Notice that the local properties for this new class include the returned case details. These local properties are needed so that later you can show the case content screen of your application with the case details.func getCase(for id: String) { PegaApi.shared.casesService.getCase(byID: id) { caseItem, error in if let error = error { self.showAlert(with: error) } else if let caseItem = caseItem { DispatchQueue.main.async { self.caseContent = caseItem.content self.currentCase = caseItem self.idLbl.text = caseItem.ID self.nameLbl.text = caseItem.name self.statusLbl.text = caseItem.status self.urgencyLbl.text = caseItem.urgency } } } }
- Override the
viewDidLoad()
method for this new class so that thegetCase()
method is always initially called displaying the given case details on the screen. Create an action connection for a View all case content button in this scene and theshowCaseContent()
method. This method references theCaseContentVC
class that displays the details for a case in another scene of the application. In addition, override theprepare(for segue:sender:)
method so that the case content to be displayed is passed to theCaseContentVC
object.Case details - Cases API