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.

NSString *title = @"NewApproval"; NSString *details = @"The approval desc..."; NSMutableArray *approvers = [[NSMutableArray alloc] init]; MMXApprovalMode *orderMode = MMXApprovalModeANY_ORDER; // Add template item if it's necessary NSMutableArray *templateItems = [[NSMutableArray alloc] init]; MMXApprovalProperty *item = [[MMXApprovalProperty alloc] init]; = @"item value"; item.value = @"100"; item.type = MMXApprovalPropertyTypeNUMBER; [templateItems addObject:item]; MMXApproval *approval = [MMXApproval createApproval:title approvalDescription:details properties:templateItems extras:nil approvers:approvers approvalMode: orderMode]; // Use channel to publish the approval MMXChannel *submissionChannel; [approval publishWithChannel:submissionChannel success:^(MMXMessage *newApproval) { // publish approval successfully } failure:^(NSError * error) { // publish approval failed }];

Listen for Incoming Approval Request or Response

The approval creator and other approvers can listen for incoming request or approval response. Both requests and responses contain an approvalID that we can use to get the approval object from the server.

[[MMXNotificationCenter defaultCenter] addWithContext:self forChannel:nil onReceive:^(MMXMessage * message) { if ([message.contentType isEqualToString: [MMXObjectIdentifier contentType]] && ((MMXObjectIdentifier *)message.payload).objectType == [MMXApproval mmxPayloadType]) { NSString *approvalID = ((MMXObjectIdentifier *) message.payload).objectID; } }];

Get Approvals Using approvalID

The following code retrieves the approval object from the server using the approvalID:

NSString *approvalID = ...; [MMXApproval approvalWithId:approvalID success:^(MMXApproval * approval) { // do something with approval object } failure:^(NSError * error) { NSLog(@"error %@", error.localizedDescription); }];

Fetch Approvals from Server

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

NSString *approvalID = ...; [MMXApproval fetchApprovals limit:10, offset:0, success:^(MMXApproval * approval) { // do something with approval object } failure:^(NSError * error) { NSLog(@"error %@", error.localizedDescription); }];

Approval Object Information Display

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

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

Accept or Reject Approval

The approver can accept or reject received approval request:

MMXApproval *approval = ...; [approval accept:@"I approve it" success:^(MMXMessage * message) { // accept approval successfully } failure:^(NSError * error) { // accept approval failed }]; // To reject the approval [approval reject:@"Sorry, I reject it" success:^(MMXMessage * message) { // reject approval successfully } failure:^(NSError * error) { // reject approval failed }];

Cancel the Approval

The approval owner can also cancel the approval.

MMXApproval *approval = ...; [approval cancel:@"The approval is cancelled" success:^(MMXMessage * message) { // cancel approval successfully } failure:^(NSError * error) { // cancel approval failed }];