Listing assignments 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 shows how to use the Connect SDK Assignment API to obtain a list of assignments for a user and obtain the details for a specific assignment.
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 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 assignments
The Assignment API provides the ability to obtain a list of assignments for a user. The following steps explain how to use the Connect SDK for this purpose.
- In the Xcode environment, click
UITableViewController
. and create a subclass of - Name the subclass
AssignmentsVC
. This subclass is where all the logic that is related to the assignments for your application is placed. It is linked to a separate scene of your application's user interface. This scene should be based on a template or be inherited from another class. - Declare an
assignments
property within this new class to represent the assignments for a specific user:var assignments = [PMAssignmentInfo]()
- Create the
getAssignments()
method for theAssignmentsVC
class. Make a call to thegetAll()
method of theassignmentsService
Connect SDK object to obtain a list of assignments for the currently authenticated or logged-in user, which is returned in the assignments completion block parameter. You can then reference this array with the returned assignments through theassignments
property for theAssignmentsVC
class:func getAssignments() { PegaApi.shared.assignmentsService.getAll { assignments, error in if let error = error { self.showAlert(with: error) } else if let assignments = assignments { self.assignments = assignments DispatchQueue.main.async { self.tableView.reloadData() } } } }
- Override the
viewWillAppear()
method for the class and call thegetAssignments()
method so that thegetAssignments()
method is called when theAssignmentsVC
view is about to appear. Override important methods inherited fromUITableViewController: tableView(_:numberOfRowsInSection:), tableView(_:cellForRowAt:), tableView(_:didSelectRowAt:), prepare(for segue:sender:)
so that the fetched assignments are presented in theAssignmentsVC
table view cells. For a preview of the implementation, see the demo project.List of assignments - Assignments API
Obtaining assignment details
The Assignment API also provides the ability to obtain the details of an assignment after you obtain a list of assignments. You use the identifier for the assignment to display its details. The following steps explain how to use the Connect SDK in your code for this purpose.
- In the Xcode environment, click
UIViewController
. > > and create a subclass of - Name the subclass
AssignmentDetailsVC
. This subclass is where all the logic that is related to the display of assignment details is placed. It is 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. - Define the
assignmentID
property, which is where the assignment identifier is passed from theAssignmentsVC
segue:var assignmentID: String?
- Add the
getAssignment()
method to the class where you call thegetAssignment()
method for theassignmentsService
Connect SDK object. This method contains one parameter that specifies the identifier of the assignment for which to obtain details. The identifier was passed from theAssignmentsVC
segue. ThegetAssignment()
method returns an assignment variable that contains the assignment details. Notice that the local properties for this new class include the returned assignment details.func getAssignment(for id: String) { PegaApi.shared.assignmentsService.getAssignment(byID: id) { assignment, error in if let error = error { self.showAlert(with: error) } else if let assignment = assignment { DispatchQueue.main.async { self.idLbl.text = assignment.ID self.nameLbl.text = assignment.name self.routedToLbl.text = assignment.routedTo self.typeLbl.text = assignment.type self.urgencyLbl.text = assignment.urgency } } } }
Assignment details - Assignment API