Skip to main content


         This documentation site is for previous versions. Visit our new documentation site for current releases.      
 

This content has been archived and is no longer being updated.

Links may not function; however, this content may be relevant to outdated versions of the product.

Listing assignments and their details with the Connect SDK on iOS

Updated on July 18, 2018

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.

This walkthrough takes approximately 25 minutes to complete.

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.

  1. In the Xcode environment, click New > File > Cocoa Touch Class and create a subclass of UITableViewController.
  2. 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.
  3. Declare an assignments property within this new class to represent the assignments for a specific user:
    var assignments = [PMAssignmentInfo]()
  4. Create the getAssignments() method for the AssignmentsVC class. Make a call to the getAll() method of the assignmentsService 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 the assignments property for the AssignmentsVC 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()
                }
            }
        }
    ​}
  5. Override the viewWillAppear() method for the class and call the getAssignments() method so that the getAssignments() method is called when the AssignmentsVC view is about to appear. Override important methods inherited from UITableViewController: tableView(_:numberOfRowsInSection:), tableView(_:cellForRowAt:), tableView(_:didSelectRowAt:), prepare(for segue:sender:) so that the fetched assignments are presented in the AssignmentsVC table view cells. For a preview of the implementation, see the demo project.

    List of assignments - Assignments API

    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.

  1. In the Xcode environment, click New > File > Cocoa Touch Class and create a subclass of UIViewController.
  2. 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.
  3. Define the assignmentID property, which is where the assignment identifier is passed from the AssignmentsVC segue:
    var assignmentID: String?
  4. Add the getAssignment() method to the class where you call the getAssignment() method for the assignmentsService 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 the AssignmentsVC segue. The getAssignment() 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
                }
            }
        }
    ​}

    Assignments details - Assignments API

    Assignment details - Assignment API

Tags

Pega Platform 7.3.1 Pega Mobile Mashup Mobile Pega Express Communications and Media Consumer Services Financial Services Government Healthcare and Life Sciences Insurance Healthcare and Life Sciences Manufacturing Consumer Services Consumer Services

Have a question? Get answers now.

Visit the Support Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

Want to help us improve this content?

We'd prefer it if you saw us at our best.

Pega.com is not optimized for Internet Explorer. For the optimal experience, please use:

Close Deprecation Notice
Contact us