Message API

Pre-built customizable chat UI - Message API's

Send Message

ALMessage * alMessage = [[ALMessage alloc] init];

    alMessage.contactIds = USER_ID;     // REPLACE USER-ID BY Receiver's userId
    alMessage.to = USER_ID;             // REPLACE USER-ID BY Receiver's userId
    alMessage.message = @"Message text here"; // REPLACE your message text
    alMessage.contentType = 0;
    alMessage.type = @"5";
    alMessage.createdAtTime = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970] * 1000];
    alMessage.deviceKey = [ALUserDefaultsHandler getDeviceKeyString];
    alMessage.sendToDevice = NO;
    alMessage.shared = NO;
    alMessage.fileMeta = nil;
    alMessage.storeOnDevice = NO;
    alMessage.key = [[NSUUID UUID] UUIDString];
    alMessage.delivered = NO;
    alMessage.fileMetaKey = nil;

    [[ALMessageService sharedInstance] sendMessages:alMessage withCompletion:^(NSString *message, NSError *error) {
        if(!error)
        {
            // WRITE YOUR LOGIC (IF - ANY)
        }
    }];
let alMessage = ALMessage()

        alMessage.contactIds = USER_ID // REPLACE USER-ID BY Receiver's userId
        alMessage.to = USER_ID // REPLACE USER-ID BY Receiver's userId
        alMessage.message = "Message text here" // REPLACE your message text
        alMessage.contentType = 0
        alMessage.type = "5"
        alMessage.createdAtTime = NSNumber(value: Double(Date().timeIntervalSince1970 * 1000))
        alMessage.deviceKey = ALUserDefaultsHandler.getDeviceKeyString()
        alMessage.sendToDevice = false
        alMessage.shared = false
        alMessage.fileMeta = nil
        alMessage.storeOnDevice = false
        alMessage.key = UUID().uuidString
        alMessage.delivered = false
        alMessage.fileMetaKey = nil
        alMessage.metadata = getNewMetaDataDictionary() // HERE DICTIONARY ADDED WITH ALMessage object

        ALMessageService.sharedInstance().sendMessages(alMessage, withCompletion: { message, error in
            if error == nil {
                // WRITE YOUR LOGIC (IF - ANY)
            }
        })

Send Message with MetaData

You can send extra information along with message text as meta-data. These key value pair can be used to do some extra processing or keep information about messages.

ALMessage * alMessage = [[ALMessage alloc] init];
    alMessage.contactIds = USER_ID;     // REPLACE USER-ID BY Receiver's userId
    alMessage.to = USER_ID;             // REPLACE USER-ID BY Receiver's userId
    alMessage.message = @"Message text here";           // REPLACE your message text
    alMessage.contentType = 0;
    alMessage.type = @"5";
    alMessage.createdAtTime = [NSNumber numberWithDouble:[[NSDate date] timeIntervalSince1970] * 1000];
    alMessage.deviceKey = [ALUserDefaultsHandler getDeviceKeyString];
    alMessage.sendToDevice = NO;
    alMessage.shared = NO;
    alMessage.fileMeta = nil;
    alMessage.storeOnDevice = NO;
    alMessage.key = [[NSUUID UUID] UUIDString];
    alMessage.delivered = NO;
    alMessage.fileMetaKey = nil;
    alMessage.metadata = [self getNewMetaDataDictionary];  // HERE DICTIONARY ADDED WITH ALMessage object

    [[ALMessageService sharedInstance] sendMessages:alMessage withCompletion:^(NSString *message, NSError *error) {
        if(!error)
        {
            // WRITE YOUR LOGIC (IF - ANY)
        }
    }];

// ADD METADATA DICTIONARY METHOD 

-(NSMutableDictionary *)getNewMetaDataDictionary 
{
    NSMutableDictionary *metaDict = [[NSMutableDictionary alloc] init];
    [metaDict setObject:@"VALUE1" forKey:@"KEY1"];
    [metaDict setObject:@"VALUE2" forKey:@"KEY2"];
    return metaDict;
}
let alMessage = ALMessage()
        alMessage.contactIds = USER_ID // REPLACE USER-ID BY Receiver's userId
        alMessage.to = USER_ID // REPLACE USER-ID BY Receiver's userId
        alMessage.message = "Message text here" // REPLACE your message text
        alMessage.contentType = 0
        alMessage.type = "5"
        alMessage.createdAtTime = NSNumber(value: Double(Date().timeIntervalSince1970 * 1000))
        alMessage.deviceKey = ALUserDefaultsHandler.getDeviceKeyString()
        alMessage.sendToDevice = false
        alMessage.shared = false
        alMessage.fileMeta = nil
        alMessage.storeOnDevice = false
        alMessage.key = UUID().uuidString
        alMessage.delivered = false
        alMessage.fileMetaKey = nil
        alMessage.metadata = getNewMetaDataDictionary() // HERE DICTIONARY ADDED WITH ALMessage object

        ALMessageService.sharedInstance().sendMessages(alMessage, withCompletion: { message, error in
            if error == nil {
                // WRITE YOUR LOGIC (IF - ANY)
            }
        })

   /// Message meta data here you can set the key value strings
   func getNewMetaDataDictionary() -> NSMutableDictionary {
        let messageMetaData = NSMutableDictionary()
        messageMetaData.setValue("VALUE1", forKey: "KEY1")
        messageMetaData.setValue("VALUE2", forKey: "KEY2")
        return messageMetaData
    }

Message With Attachment

You can use below method to send message with attachments and download and receive download/upload progress.

🚧

Important

You need to save the attachment to document directory using utility methods of ALImagePickerHandler just like we are doing in below sample code.

ALMessageServiceWrapper * wrapperService  = [ALMessageServiceWrapper new];

//build message Objects
ALMessage * almessage = [wrapperService createMessageEntityOfContentType:ALMESSAGE_CONTENT_ATTACHMENT toSendTo:@"receiverContact" withText:@"Text"];

//get file path of attachment
UIImage *image = [UIImage imageNamed:@"IMGE_NAME"]; 
NSString * filePath = [ALImagePickerHandler saveImageToDocDirectory:image];

[wrapperService sendMessage:almessage withAttachmentAtLocation:filePath andWithStatusDelegate:self andContentType:ALMESSAGE_CONTENT_ATTACHMENT];

Following attachment types are supported in our pre-built UI ::

  • Audio
  • Video
  • PDF
  • Image
  • GIF
  • DOC
  • Location (See this to send location)
  • Contact

You will have to do minor changes in above code for sending different types of attachment.

// For sending Audio use content-type
[wrapperService sendMessage:almessage withAttachmentAtLocation:filePath andWithStatusDelegate:self andContentType:ALMESSAGE_CONTENT_AUDIO];

// For sending Video/Image/PDF/Doc/GIF use content-type
[wrapperService sendMessage:almessage withAttachmentAtLocation:filePath andWithStatusDelegate:self andContentType:ALMESSAGE_CONTENT_ATTACHMENT];


// For sending Contact use content-type
[wrapperService sendMessage:almessage withAttachmentAtLocation:filePath andWithStatusDelegate:self andContentType:ALMESSAGE_CONTENT_VCARD];

📘

Note: If you upload a file on our servers then there is a size limit of 100 MB. This limit can be increased on request.

Download Attachment

ALMessageServiceWrapper * wrapperService  = [ALMessageServiceWrapper new];
wrapperService.messageServiceDelegate = self;
wrapperService downloadMessageAttachment:alMessage];

Upload/Download Delegates

// bytes downloaded  
-(void)updateBytesDownloaded:(NSUInteger) bytesReceived;

//bytes uploaded 
-(void)updateBytesUploaded:(NSUInteger) bytesSent;

//download OR upload  failed 
-(void)uploadDownloadFailed:(ALMessage*)alMessage;

//upload completed 
-(void)uploadCompleted:(ALMessage *) alMessage;

//download completed
-(void)DownloadCompleted:(ALMessage *) alMessage;

Messages list

Get latest messages from each conversation

  • Implement ALMessagesDelegate delegate in your controller.
ALMessageDBService * dBService = [ALMessageDBService new];
  dBService.delegate = self; // Controller reference for ALMessagesDelegate delegate
  [dBService getMessages:self.nil];
  • Add below code to get the latest messages in your controller.
//Delegate method.
   -(void)getMessagesArray:(NSMutableArray*)messagesArray{

     //messageArray contains array of ALMessage object
   }

Get latest message for user or group

  • For User
ALMessageService *msgService = [[ALMessageService alloc] init];
ALMessage * msgService = [msgService getLatestMessageForUser:@"USER_ID"];
  • For Group
ALMessageService *msgService = [[ALMessageService alloc] init];
ALMessage * = [msgService getLatestMessageForChannel:[NSNumber numberWithInt:<GROUP_ID>] excludeChannelOperations:NO];

📘

IF excludeChannelOperations is passed as 'YES' , it will exclude all group notification messages. e.g; Group create/add member/remove member etc.

Build your UI from scratch - Message API's

It has convenient methods for sending a message like a text, attachment in one to one chat and group chat conversation

📘

Setup ApplozicClient

Note: You need to setup ApplozicClient before using the methods refer to this link

Send a text message in one to one chat

Sending a message to the user, you need to pass userId and the message text to send.

ALMessage *alMessage = [ALMessage build:^(ALMessageBuilder * alMessageBuilder) {
        alMessageBuilder.to = @"userId"; //Pass userId to whom you want to send a message
        alMessageBuilder.message = @"messageText"; //Pass message text here
        
    }];
    
    [self.applozicClient sendTextMessage:alMessage withCompletion:^(ALMessage *message, NSError *error) {
        
        if(!error){
            //Update the ui message is sent to server
        }
        
    }];
let alMessage = ALMessage.build({ alMessageBuilder in
  alMessageBuilder?.to = "userId" //pass userId to whom you want to send a message
  alMessageBuilder?.message = "Message text here" // Pass message text         
    })
        applozicClient.sendTextMessage(alMessage, withCompletion: { (alMessage, error) in
            
            if(error == nil){
                //update the ui once message is sent
            }
           
        })

Send a text message in channel/group chat

Sending a message to the channel/group, you need to pass channelKey and the message text to send.

// Message builder
ALMessage *alMessage = [ALMessage build:^(ALMessageBuilder * alMessageBuilder) {
        alMessageBuilder.groupId = @"<pass channel id>";
        alMessageBuilder.message = "Test message";    
}];
    
// Pass an `ALMessage` object to this method.
[self.applozicClient sendTextMessage:alMessage withCompletion:
 ^(ALMessage *message, NSError *error) {
        
    if(!error){
        NSLog("Success: Message sent 🎉");
    }       
}];
// Message builder
let alMessage = ALMessage.build({ alMessageBuilder in
 
        guard let messageBuilder = alMessageBuilder else { return }
        messageBuilder.groupId = pass channel key;
        messageBuilder.message = "Test message" //Pass message text here
})

// Pass an `ALMessage` object to this method.
applozicClient.sendTextMessage(alMessage, withCompletion: { (alMessage, error) in       
    if(error == nil){
        print("Success: Message sent 🎉")
    }
})

Attachment sending in chat

This section will guide you can send an attachment to user or group with the progress of the upload

Following attachment types are supported

  • Audio
  • Video
  • PDF
  • Image
  • GIF
  • DOC
  • Location
  • Contact

Message Content type:

This is the message content type you can use based on the types we have enum. You need to pass the below content type to message builder contentType based on the type you use.

Attachment

Content Type

type

Audio voice message

ALMESSAGE_CONTENT_VCARD

int

Contact message

ALMESSAGE_CONTENT_VCARD

int

Location message

ALMESSAGE_CONTENT_LOCATION

int

Message text

ALMESSAGE_CONTENT_DEFAULT

int

Attachments like video and other files

ALMESSAGE_CONTENT_ATTACHMENT

int

📘

Note: If you upload a file on our servers then there is a size limit of 100 MB. This limit can be increased on request.

Send an attachment message in one to one chat

Sending a message to the user you need to pass userId and pass full filePath of the attachment

🚧

Important

The file name you use to send attachment must be present in the document directory. You can use utility methods of ALImagePickerHandler to save image/gif/video to document directory and get the name from the path and set it to imageFilePath.

You need to implement the ApplozicAttachmentDelegate in your class where you want to get the callback status of uploaded.

#import <Applozic/Applozic.h>

@interface ViewController ()<ApplozicAttachmentDelegate>
import Applozic

class ViewController:ApplozicAttachmentDelegate {
self.applozicClient.attachmentProgressDelegate = self;
     
     ALMessage *alMessage = [ALMessage build:^(ALMessageBuilder * alMessageBuilder) {
        alMessageBuilder.to = @"userId"; // Pass userId to whom you want to send a message
        alMessageBuilder.imageFilePath = @"Pass the name of the file"; // File name
        alMessageBuilder.contentType = ALMESSAGE_CONTENT_ATTACHMENT;
        
    }];

     [self.applozicClient sendMessageWithAttachment:alMessage];
applozicClient.attachmentProgressDelegate = self
        
        let alMessage = ALMessage.build({ alMessageBuilder in
            alMessageBuilder?.to = "userId" //Pass userId to whom you want to send a message
            alMessageBuilder?.imageFilePath = "pass file name here" // file name here
          alMessageBuilder?.contentType = Int16(ALMESSAGE_CONTENT_ATTACHMENT)

        })
        
        applozicClient.sendMessage(withAttachment: alMessage)

Note: Make sure to save the file in the document directory
Example: If the complete path of the document directory looks like below :

/Users/*****/Library/Developer/CoreSimulator/Devices/A309B7BF-FC18-4715-B596-87902B2AC34D/data/Containers/Data/Application/CB009E81-E3AE-4AEA-9326-0C58E4B99D2C/Documents/IMG-1591949383655.868164.jpeg

Here the name will be IMG-1591949383655.868164.jpeg you need to pass the name of the file in message builder

Example: As you can see below the name of the file is passed in builder

alMessageBuilder.imageFilePath = @"IMG-1591949383655.868164.jpeg*";
alMessageBuilder?.imageFilePath = "IMG-1591949383655.868164.jpeg" // file name here

Send an attachment message in channel/group chat

Sending a message to the group/channel you need to pass channelKey and pass full filePath of the attachment

applozicClient.attachmentProgressDelegate = self;
    
    ALMessage *alMessage = [ALMessage build:^(ALMessageBuilder * alMessageBuilder) {
        alMessageBuilder.groupId = channelKey; // Pass channelKey to channel/group  you want to send a attchment message
        alMessageBuilder.imageFilePath = @"Pass Name of the file; // Name of the  File.
        alMessageBuilder.contentType = ALMESSAGE_CONTENT_ATTACHMENT;
        
    }];
    
    [self.applozicClient sendMessageWithAttachment:alMessage];
applozicClient.attachmentProgressDelegate = self;

    let alMessage = ALMessage.build({ alMessageBuilder in
        alMessageBuilder?.groupId = channelKey // pass channel/group to whom you want to send a message
            alMessageBuilder?.imageFilePath = "pass file name here" // Name of the file
            alMessageBuilder?.contentType = Int16(ALMESSAGE_CONTENT_ATTACHMENT)
             
        })
        
        applozicClient.sendMessage(withAttachment: alMessage)

Example: If the complete path of the document directory looks like below :

/Users/*****/Library/Developer/CoreSimulator/Devices/A309B7BF-FC18-4715-B596-87902B2AC34D/data/Containers/Data/Application/CB009E81-E3AE-4AEA-9326-0C58E4B99D2C/Documents/IMG-1591949383655.868164.jpeg

Here the name will be IMG-1591949383655.868164.jpeg you need to pass the name of the file in message builder

Example: As you can see below the name of the file is passed in builder

alMessageBuilder.imageFilePath = @"IMG-1591949383655.868164.jpeg";
alMessageBuilder?.imageFilePath = "IMG-1591949383655.868164.jpeg"

Handling progress while sending an attachment

For progress callbacks, implement ApplozicAttachmentDelegate in your Appdelegate or ViewController where you are using send a message:

For example, in your ViewController or Appdelegate file, you can implement like below to get callbacks of delegate methods:

#import <Applozic/Applozic.h>

@interface ViewController ()<ApplozicAttachmentDelegate>

@end
  
@implementation ViewController
  
  - (void)onDownloadCompleted:(ALMessage *)alMessage {
    // Will get this callback once attachment is downloaded. it will give message object
    // Ignore this in case of upload a attachment
}

- (void)onDownloadFailed:(ALMessage *)alMessage {
  // Will get this callback once attachment  Download failed. it will give message object the message which is failed to download

}

- (void)onUpdateBytesDownloaded:(int64_t)bytesReceived withMessage:(ALMessage *)alMessage {

    // Will get this callback on downloaded bytes in attachment and  from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
    // Ignore this in case of upload a attachment
}

- (void)onUpdateBytesUploaded:(int64_t)bytesSent withMessage:(ALMessage *)alMessage {
 // Will get this callback while uploading it will have bytesSent and from alMessage you can get the filePath and find that file in your doc directory to get the size of the file

}

- (void)onUploadCompleted:(ALMessage *)alMessage withOldMessageKey:(NSString *)oldMessageKey {
 // You can use the oldMessageKey to update the current message in UI you can replace the messsage by finding the message with oldMessageKey in your  message list
}

- (void)onUploadFailed:(ALMessage *)alMessage {
    // Will get this callback in case of upload failed
}

@end
import Applozic

class ViewController:ApplozicAttachmentDelegate {

public func onUpdateBytesDownloaded(_ bytesReceived: Int64, with alMessage: ALMessage!) {
        // Will get this callback on downloaded bytes in attachment and  from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
        // Ignore this in case of upload a attachment
    }


    public func onUpdateBytesUploaded(_ bytesSent: Int64, with alMessage: ALMessage!) {
      // Will get this callback while uploading it will have bytesSent and from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
    }

    public func onUploadFailed(_ alMessage: ALMessage!) {
      // Will get this callback in case of upload failed
    }

    public func onDownloadFailed(_ alMessage: ALMessage!) {
           // Will get this callback once attachment  Download failed. it will give message object the message which is failed to download
    }

    public func onUploadCompleted(_ alMessage: ALMessage!, withOldMessageKey oldMessageKey: String!) {
        // You can use the oldMessageKey to update the current message in UI you can replace the messsage by finding the message with oldMessageKey in your  message list
    }

    public func onDownloadCompleted(_ alMessage: ALMessage!) {
        // Will get this callback once attachment is downloaded. it will give message object
        // Ignore this in case of upload a attachment

    }
    
}

Sending a location to show the map in the chat

Sending a location message in chat for showing a map view you can pass latitude and longitude values and message object alMessageBuilder.message will have JSON string of the latitude and longitude.

NSString * lat = [NSString stringWithFormat:@"%.8f",latitude];//Pass latitude here 
    NSString * lon = [NSString stringWithFormat:@"%.8f",longitude];//Pass longitude here 
    
    NSDictionary * latLongDic = [[NSDictionary alloc] initWithObjectsAndKeys:lat,@"lat",lon,@"lon", nil];
    
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:latLongDic
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    NSString *jsonString = nil;
    if(jsonData){
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    
    
    ALMessage *alMessage = [ALMessage build:^(ALMessgaeBuilder * alMessageBuilder) {
        alMessageBuilder.to = userId; //Pass userId you want to send a message
      
    //or alMessageBuilder.groupId = channelKey; //Pass channelKey to channel you want to send a message and remove alMessageBuilder.to code 

        alMessageBuilder.message = jsonString; //Pass message text here
        alMessageBuilder.contentType = ALMESSAGE_CONTENT_LOCATION;
        
    }];
    
    [self.applozicClient sendTextMessage:alMessage withCompletion:^(ALMessage *message, NSError *error) {
        
        if(!error){
            //Update the ui message is sent to server
        }
        
    }
let lat = String(format: "%.8f", latitude) // Pass float value
   let lon = String(format: "%.8f", longitude)  // Pass float value

        let latLongDic = [
            "lat" : lat,
            "lon" : lon
        ]

        var error: Error?
        
        let applozicClient =   ApplozicClient (applicationKey: "applozic-sample-app") as ApplozicClient
        
        let jsonData: Data? = try? JSONSerialization.data(withJSONObject: latLongDic, options: .prettyPrinted)
        
        var jsonString: String? = nil
        
        if jsonData != nil {
            if let aData = jsonData {
                jsonString = String(data: aData, encoding: .utf8)
            }
        }
        
        
        let alMessage = ALMessage.build({ alMessageBuilder in
            alMessageBuilder?.to = "userId" //pass userId to whom you want to send a message
            // or alMessageBuilder?.groupId = channelKey; //Pass channelKey to channel you want to send a message and remove alMessageBuilder.to code 
            alMessageBuilder?.message = jsonString
            alMessageBuilder?.contentType = Int16(ALMESSAGE_CONTENT_LOCATION)
            
        })
        applozicClient.sendTextMessage(alMessage, withCompletion: { (alMessage, error) in
            
            if(error == nil){
                //update the ui once message is sent
            }
            
        })

Handling the attachment download

This will guide you to download an attachment with the progress of the download

self.applozicClient.attachmentProgressDelegate = self;
[self.applozicClient downloadMessageAttachment:alMessage]; // Pass message object to download
applozicClient.attachmentProgressDelegate = self

 applozicClient.downloadMessageAttachment(alMessage) //Pass message object to download

For download progress callbacks, implement ApplozicAttachmentDelegate in your Appdelegate or ViewController where you are downloading an attachment.

For example, in your ViewController or Appdelegate file, you can implement like below to get callbacks of delegate methods to download the attachment:

//In .m file 

#import <Applozic/Applozic.h>

@interface ViewController ()<ApplozicAttachmentDelegate>

@end
  
@implementation ViewController
  
 - (void)onDownloadCompleted:(ALMessage *)alMessage {
    // Will get this callback once attachment is downloaded. it will give message object
    // Ignore this in case of upload a attachment
}

- (void)onDownloadFailed:(ALMessage *)alMessage {
  // Will get this callback once attachment  Download failed. it will give message object the message which is failed to download

}

- (void)onUpdateBytesDownloaded:(int64_t)bytesReceived withMessage:(ALMessage *)alMessage {

    // Will get this callback on downloaded bytes in attachment and  from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
    // Ignore this in case of upload a attachment
}

- (void)onUpdateBytesUploaded:(int64_t)bytesSent withMessage:(ALMessage *)alMessage {
 // Will get this callback while uploading it will have bytesSent and from alMessage you can get the filePath and find that file in your doc directory to get the size of the file

}

- (void)onUploadCompleted:(ALMessage *)alMessage withOldMessageKey:(NSString *)oldMessageKey {
 // You can use the oldMessageKey to update the current message in UI you can replace the messsage by finding the message with oldMessageKey in your  message list
}

- (void)onUploadFailed:(ALMessage *)alMessage {
    // Will get this callback in case of upload failed
}

  
@end
import Applozic

class ViewController:ApplozicAttachmentDelegate {

  public func onUpdateBytesDownloaded(_ bytesReceived: Int64, with alMessage: ALMessage!) {
        // Will get this callback on downloaded bytes in attachment and  from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
        // Ignore this in case of upload a attachment
    }


    public func onUpdateBytesUploaded(_ bytesSent: Int64, with alMessage: ALMessage!) {
      // Will get this callback while uploading it will have bytesSent and from alMessage you can get the filePath and find that file in your doc directory to get the size of the file
    }

    public func onUploadFailed(_ alMessage: ALMessage!) {
      // Will get this callback in case of upload failed
    }

    public func onDownloadFailed(_ alMessage: ALMessage!) {
           // Will get this callback once attachment  Download failed. it will give message object the message which is failed to download
    }

    public func onUploadCompleted(_ alMessage: ALMessage!, withOldMessageKey oldMessageKey: String!) {
        // You can use the oldMessageKey to update the current message in UI you can replace the messsage by finding the message with oldMessageKey in your  message list
    }

    public func onDownloadCompleted(_ alMessage: ALMessage!) {
        // Will get this callback once attachment is downloaded. it will give message object
        // Ignore this in case of upload a attachment

    }
    
}

Message read and delivered information for group

The message read and delivered members list you can get using the below method need to call this method with the message key replace <MESSAGE_KEY> with message key of message object.

#import <Applozic/Applozic.h>

  
 NSMutableArray * readList = [NSMutableArray new];
    NSMutableArray * deliveredList = [NSMutableArray new];

    ALMessageService *msgService = [ALMessageService new];
    [msgService getMessageInformationWithMessageKey:@"<MESSAGE_KEY>" withCompletionHandler:^(ALMessageInfoResponse *msgInfo, NSError *theError) {

        if (!theError) {
            NSMutableArray *arrayList = [NSMutableArray arrayWithArray:msgInfo.msgInfoList];

            for (ALMessageInfo *info in arrayList) {

                if (info.status == (short)READ ||
                    info.status == DELIVERED_AND_READ) {
                    NSLog(@"User id of the read member %@", info.userId);
                    [readList addObject:info];
                }

                if(info.status == (short)DELIVERED) {
                    NSLog(@"User id of the DELIVERED member %@", info.userId);
                    [deliveredList addObject:info];
                }
            }
        }
    }];
let readList = NSMutableArray()
        let deliveredList = NSMutableArray()

        let msgService = ALMessageService()
        msgService.getMessageInformation(withMessageKey: "<MESSAGE_KEY>", withCompletionHandler: { msgInfo, theError in

            if theError == nil {
                var arrayList = NSMutableArray()
                if let msgInfoList = msgInfo?.msgInfoList {
                    arrayList = msgInfoList
                    for info in arrayList {
                        guard let info = info as? ALMessageInfo else {
                            continue
                        }

                        if info.status == Int16(1) || info.status == Int16(5) {
                            print("User id of the read \(String(describing: info.userId))")
                            readList.add(info)
                        }


                        if info.status == Int16(4) {
                            print("User id of the DELIVERED to \(String(describing: info.userId))")
                            deliveredList.add(info)
                        }
                    }
                }
            }
        })

What’s Next
Did this page help you?