One On One Chat

The Methods below are available for One-on-one chat:

Method Description
setStatus Sets a status for logged-in user
setStatusMessage Sets a status message for logged-in user
getUserInfo Allows logged-in user to pull details of other user
getOnlineUsers Gets list of online users from the server
sendMessage Allows logged-in user to send a message to other user
sendImage Allows logged-in user to send an image to other user
sendVideo Allows logged-in user to send a video to other user
sendAudioFile Allows logged-in user to send an audio to other user
sendSticker Allows logged-in user to send a sticker to currently opened group chat
sendFile Allows logged-in user to send a file
getChatHistory Gets chat history with another user
broadcastMessage Allows logged-in Send a text message to more than one user
isTyping Sends the typing notification to other users. This feature works only with CometService
sendDeliverdReceipt Sends the message delivery receipt to the sender of the message
sendReadReceipt Sends the message read receipt to the sender of the message
getAllAnnouncements Pulls the announcements from server
blockUser Blocks a user
getBlockedUserList Gets the list of blocked users
unblockUser Unblocks a user
setTranslateLanguage Set the language for real time translation
getPluginInfo Gets the details of the enabled plugins
isUserLoggedIn Return true for when user is logged-in

setStatus

CometChat allows you to set the status for your profile. You can set any one of the “Available”, “Busy”, “Invisible”, “Offline” status. Method Signature:

- (void)setStatus:(NSInteger)statusOption
          success:(void(^)(NSDictionary *response))response
          failure:(void(^)(NSError *error))failure;

Example:

[cometChat setStatus:STATUS_BUSY success:^(NSDictionary *response) {
     /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
statusOption status to set on profile
callback success and failure callbacks

Response for successCallback:

{
    message: "status updated"
}

setStatusMessage

Method Signature:

- (void)setStatusMessage:(NSString *)statusMessage
                    success:(void(^)(NSDictionary *response))response
                    failure:(void(^)(NSError *error))failure;

Example:

[cometChat setStatusMessage:@"What a beautiful day!!" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
   /* Code Block */
}];

Arguments:

Argument Description
statusMessage status message to set on profile
callback success and failure callbacks

Response for successCallback:

{ 
    message: "status message updated" 
}

getUserInfo

Allows logged-in user to fetch details of any user. Method Signature:

- (void)getUserInfo:(NSString *)userId
            success:(void(^)(NSDictionary *response))response
            failure:(void(^)(NSError *error))failure;

Example:

[cometChat getUserInfo:@"12" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
userId recipient’s user id
callback success and failure callbacks

Response for successCallback:

{
    "id": "12",
    "n": "Jon Snow",
    "l": "",
    "d": "0",
    "a": "",
    "s": "offline",
    "m": "Wonderful day",
    "ch": "cc735e0970a1e82bb6738e59b881cb23",
    "ls": "1451218483",
    "lstn": "0"
}

getOnlineUsers

You can get the user list whenever you require. Method Signature:

- (void)getOnlineUsers:(void(^)(NSDictionary *response))response
               failure:(void(^)(NSError *error))failure;

Example:

[cometChat getOnlineUsers:^(NSDictionary *response) {
      /* Code Block */ 
 } failure:^(NSError *error) {
     /* Code Block */  
 }];

Arguments:

Argument Description
callback success and failure callbacks

Response for successCallback:

{
    {
        "id": "1","n": "User1", "a": "avatar.png", "d": "1", "s": "available","m": "I'm available"
    },
    {
        "id": "2", "n": "User2", "a": "avatar.png", "d": "1",  "s": "available","m": "I'm available"
    }
}

sendMessage

Allows logged-in user to send message to other users. Method Signature:

- (void)sendMessage:(NSString *)message
               toId:(NSString *)toId
            localID:(NSString *)localID
            isGroup:(BOOL)isGroup
            success:(void(^)(NSDictionary *response))response
            failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendMessage:@"Hi! How are you?" toId:@"15" localID:@"50" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID a parameter which is returned to you with the response to keep track of the status of the message sent
toId recipient’s user id
message text message
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{  
    "id": 71,
    "localmessageid": 50,
    "m": "Hi! How are you?"
}

sendImage

Allows logged-in user to send an image using Bitmap or filepath

Sending a image data

Method Signature:

- (void)sendImageWithData:(NSData *)imageData
                     toId:(NSString *)toId
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendImageWithData:imageData toId:@"15" localID:@"50" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
imageData NSData of the image
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid":101,
}

Sending an image using file path

Method Signature:

- (void)sendImageWithPath:(NSString *)imagePath
                     toId:(NSString *)toId
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendImageWithPath:@"/Documents/IMG1049.JPG" toId:@"12" localID:@"50" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
imagePath image path from storage
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid":201,
    "original_file": "/Documents/IMG1049.JPG"
}

sendVideo

Allows logged-in user to send a video Method Signature:

- (void)sendVideoWithPath:(NSString *)videoPath
                     toId:(NSString *)toId
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendVideoWithPath:@"/Documents/Video.mp4" toId:@"15" localID:@"50" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
videoPath path of the file
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid":301,
    "original_file": "/Documents/Video.mp4",
}

sendAudioFile

Allows logged-in user to send an audio file or recorded audio notes

Method Signature:

- (void)sendAudioWithPath:(NSString *)audioPath
                     toID:(NSString *)toID
                  localID:(NSString *)localID
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendAudioWithPath:@"/Documents/audio1.aac" toId:@"15" localID:@"50" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localId A unique value that is returned to you in the response to keep track of the status of the message
audioPath audio file from storage
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

Response for successCallback:

{
    "id": 23,
    "localmessageid":501,
    "original_file": "/Documents/audio1.aac"
}

sendSticker

Allows the user to send a sticker.

Method signature:

- (void)sendStickers:(NSString *)stickerName
                toId:(NSString *)toId
             localID:(NSString *)localID
             isGroup:(BOOL)isGroup
             success:(void(^)(NSDictionary *response))response
             failure:(void(^)(NSError *error))failure;


Example:

[cometChat sendStickers:@"bear_1" toId:@"15" localID:@"501" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
localID A unique value that is returned to you in the response to keep track of the status of the message
stickerName Sticker name
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

sendFile

Allows the logged in user to send a file.

Method Signature:

- (void)sendFile:(NSString *)filePath
                     toId:(NSString *)toId
                  localId:(NSString *)localId
                  isGroup:(BOOL)isGroup
                  success:(void(^)(NSDictionary *response))response
                  failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendFile:@"Path of File To Be Sent" toId:@"15" localID:@"501" isGroup:NO success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Argument Description
localId A unique value that is returned to you in the response to keep track of the status of the message
filePath file to be sent
toId recipient’s user id
isGroup is recipient group or user
callback success and failure callbacks

getChatHistory

Allows logged-in user to get the previous message

Method Signature:

- (void)getChatHistory:(NSString *)userId
             messageId:(NSString *)messageId
               success:(void(^)(NSDictionary *response))success
               failure:(void(^)(NSError *error))failure;

Example:

[cometChat getChatHistory:@"10" messageId:@"102" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
userId recipient’s user id
messageId last message id
callback success and failure callbacks

Response for successCallback:

{
  history : [
   { 
     from = 14; id = 4843;  message = "HI"; "message_type" = 10; old = 1;  self = 1;  sent = 1429771974000;
   },
   { 
     from = 14; id = 4844;  message = "Hello"; "message_type" = 10; old = 1;  self = 1;  sent = 1429772345000;
   },
  .
  .
 ]
}

broadcastMessage

Allows logged-in user to send a message to more than one users Method Signature:

- (void)broadcastMessage:(NSString *)message
                 toUsers:(NSArray *)usersId
                 success:(void(^)(NSDictionary *response))response
                 failure:(void(^)(NSError *error))failure;

Example:

NSArray *users = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
[cometChat broadcastMessage:@"Hi! How are you?" toUsers:users success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
message message text
users recipient user’s array
callback success and failure callbacks

Response for successCallback:

{
    [
        {  "id": 71, "to":1,  "m": "Hi! How are you?" },
        {  "id": 72, "to":2,  "m": "Hi! How are you?" },
        {  "id": 73, "to":3,  "m": "Hi! How are you?" }
    ]
}

isTyping

Allows logged-in user to send an typing notification Method Signature:

- (void)isTyping:(BOOL)istyping
         channel:(NSString *)channel
         failure:(void(^)(NSError *error))failure;

Example:

[cometChat isTyping:YES channel:@"49086e3ef2d52d104fa0bc7cade215cf" failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
isTyping This is boolean value , pass true when you start typing, pass false when you stop typing
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

sendDeliverdReceipt

Allows logged-in user to notify message delivery to the sender. Method Signature:

- (void)sendDeliverdReceipt:(NSString *)msgID
                    channel:(NSString *)channel
                    failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendDeliverdReceipt:@"5" channel:@"49086e3ef2d52d104fa0bc7cade215cf" failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
msgID id for the received message
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

sendReadReceipt

Allows logged-in user to notify to the sender that the message has been read. Method Signature:

- (void)sendReadReceipt:(NSString *)msgID
                channel:(NSString *)channel
                failure:(void(^)(NSError *error))failure;

Example:

[cometChat sendReadReceipt:@"5" channel:@"49086e3ef2d52d104fa0bc7cade215cf" failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
msgID id for the received message
channel This is the channel id to whom you are chatting with. You will get the channel from the user list as “ch” channel when you enable the CometService
callback Will result in fail callback if CometService is not enabled for your site

getAllAnnouncements

Gets all the announcements added by CometChat admin. Method Signature:

- (void)getAllAnnouncements:(void (^)(NSDictionary *response))response
                    failure:(void (^)(NSError *error))failure;

Example:

[cometChat getAllAnnouncements:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
callback success and failure callbacks

Response for successCallback:

{
  "_2":
    { "id": "2", "m": "Test 2", "t": "1416576762"},
  "_1":
    { "id": "1", "m": "Announcements test","t": "1416576743" }
}

blockUser

Allows logged-in user to block a user Method Signature:

- (void)blockUser:(NSString *)userID
          success:(void(^)(NSDictionary *response))success
          failure:(void(^)(NSError *error))failure;

Example:

[cometChat blockUser:@"15" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
userID recipient id to be block
callback success and failure callbacks

Response for successCallback:

{
    "id": "15"
}

Description:

Response Proprty Description
id userid of blocked user

getBlockedUserList

Allows logged-in user to send an audio file or recorded audio notes Method Signature:

- (void)getBlockedUserList:(void(^)(NSDictionary *response))success
                            failure:(void(^)(NSError *error))failure;

Example:

[cometChat getBlockedUserList:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Response for successCallback:

{
    "73": { "id": "73", "name": "user73" },
    "700": { "id": "70", "name": "user70" }
}

Description:

Response Property Description
callback success and failure callbacks

unblockUser

Allows logged-in user to unblock a user Method Signature:

- (void)unblockUser:(NSString *)userID
            success:(void(^)(NSDictionary *response))success
            failure:(void(^)(NSError *error))failure;

Example:

[cometChat unblockUser:@"15" success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
userID recipient id to be unblock
callback success and failure callbacks

Response for successCallback:

{
    "id": "15"
}

Description:

Response Proprty Description
id userid of unblocked user

setTranslateLanguage

Allows logged-in user to set a language for real time translation Method Signature:

- (void)setTranslateLanguage:(NSInteger)language
                     success:(void(^)(NSDictionary *response))response
                     failure:(void(^)(NSError *error))failure;

Example:

[cometChat setTranslateLanguage:Spanish success:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Arguments:

Argument Description
ENUM a value from Languages enum
Callbacks Callback Methods

Response for successCallback:

{
    "Selected language": "Spanish"
}

getPluginInfo

Gets the enabled status for the plugins Method Signature:

- (void)getPluginInfo:(void (^)(NSDictionary *response))response
              failure:(void (^)(NSError *error))failure;

Example:

[cometChat getPluginInfo:^(NSDictionary *response) {
    /* Code Block */
} failure:^(NSError *error) {
    /* Code Block */
}];

Response for successCallback:

{
    "avchat_enabled": "1",
    "audiochat_enabled": "1",
    "createchatroom_enabled": "1",
    "blockuser_enabled": "0",
    "mediasharing_enabled": "1",
    "chatroom_mediasharing_enabled": "1",
    "realtime_translate_enabled": "0"
}

isUserLoggedIn

Return true if user has logged-in Method Signature:

- (BOOL)isUserLoggedIn()

Example:

[cometChat isUserLoggedIn];

  • Was this helpful?
  • Yes   No