An approval allows you to send a request to one or multiple approvers through a channel. Approvers can review information associated with the approval and accept or reject the approval. You will receive response results from each approver. The approval-related APIs are described below.

Create an Approval

The following example shows how to create an approval named NewApproval.

var title = "NewApproval" var details = "The approval desc..." var approvers:[MMUser] = [approverUsers] var orderMode:MMXApprovalMode = MMXApprovalMode.ANY_ORDER // Add template item if it's necessary var templateItems:[MMXApprovalProperty] = [] let item = MMXApprovalProperty(name:"item value" , optional: false, value:"100", type: .MMXApprovalPropertyTypeNUMBER) templateItems.append(item) let approval = MMXApproval.createApproval(title, approvalDescription: details, properties: templateItems, extras: nil, approvers: approvers, approvalMode: orderMode) // Add attachment if it's necessary let attachment = MMAttachment(data: UIImageJPEGRepresentation(image, 0.01)!, mimeType: "image/png") approval.addAttachment(attach) // Use channel to publish the approval var submissionChannel:MMXChannel approval?.publish(channel: submissionChannel, success: { message in // publish approval successfully }) { (error) in // publish approval failed }

Listen for Incoming Approval Request or Response

The approval creator and other approvers can listen for an incoming request or approval response. Both requests and responses contain an approvalID that we can use to get the approval object from the server. self, forChannel: nil, onReceive: { message in if let objectIdentifier = message.payload as? MMXObjectIdentifier, objectIdentifier.objectType == MMXApproval.mmxPayloadType() { // receive approval updates let approvalID = objectIdentifier.objectID // get approvalID ... } })

Get Approvals Using approvalID

Get the approval object from the server using the approvalId.

let approvalID = ...; MMXApproval.approvalWithId(approvalID, success: { approval in // do something with approval object }, failure: { error in //print("error \(error.localizedDescription)") })

Fetch Approvals from Server

The following code fetches the assigned approval objects from the server.

MMXApproval.fetchApprovals(withFiltersForAssignedApprovals: MMXApprovalFilter(statuses:[MMXApprovalStatus]()), filtersForMyApprovals: MMXApprovalFilter(statuses:[MMXApprovalStatus]()), limit: 10, offset: 0, success: { approvals in // fetch approvals successfully }) { (error) in // fetch approvals successfully }

Approval Object Information Display

The approval object contains all the information needed to display in your user interface.

let name = // A user-friendly name of the approval. let details = myApproval.details // The details information of the approval. let status = myApproval.status // Status of the approval, which includes APPROVED, DELETED, PENDING, REJECTED, RESUBMITTED, CANCELED let approvers = myApproval.approvers // approvers objects for the approval let extras = myApproval.extras // A user-defined object used to store arbitrary data will can accessed from the approval instance. let updatedDate = myApproval.updatedDate // Latest updated date of the approval

Accept or Reject Approval Request

Approvers can either accept or reject an approval request, as shown below:

var myApproval:MMXApproval // To accept the approval myApproval.accept("I approve it", success: { (message) in // accept approval successfully }, failure: { (error) in // accept approval failed }) // To reject the approval myApproval.reject("Sorry, I reject it", success: { (message) in // reject approval successfully }, failure: { (error) in // reject approval failed })

Cancel Approval

The approval owner can also cancel the approval.

myApproval.cancel("The approval is cancelled", success: { (message) in // cancel approval successfully }, failure: { (error) in // cancel approval failed })