One-on-One

To add One-on-One Chat support in your application,

Include the class <MessageSDKFramework/CometChat.h> in the .h file of your class.

All the method calls will invoke their respective callback blocks as defined below.

1. Initialize CometChat object

CometChat *cometchat =  [[CometChat alloc] initWithAPIKey:@""];

2. Subscribe to CometChat

Start receiving messages, user’s list and logged-in user’s profile data. mode signifies receiving messages with emoji support.

- (void)subscribeWithMode:(BOOL)mode
         onMyInfoReceived:(void (^)(NSDictionary *))myInfo
         onGetOnlineUsers:(void (^)(NSDictionary *))onlineUsers
        onMessageReceived:(void (^)(NSDictionary *))message
   onAnnouncementReceived:(void (^)(NSDictionary *))announcement
  onAVChatMessageReceived:(void (^)(NSDictionary *))avchatMessage
  onActionMessageReceived:(void (^)(NSDictionary *))actionMessage
             onGetBotList:(void (^)(NSDictionary *))botList
                  failure:(void (^)(NSError *))failure;

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))myInfo
Invocation: When server sends an update related to logged-in user’s profile
Response: NSDictionary containing the current user’s profile.
Eg:

{
    "id"="5";
    "n"="MyName";
    "l"="MyLastName";
    "a"="avatar.png";
    "s"="available";
    "m"="I'm available";
}

(ii) (void(^)(NSDictionary *response))onlineUsers
Invocation: When the server sends an updated user’s list
Response: NSDictionary containing the user’s list.
Eg:

{
    "_1" = {
        "id"="1";
        "n"="User1";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
	
    "_2" = {
        "id"="2";
        "n"="User2";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
}

(iii) (void(^)(NSDictionary *response))message
Invocation: When a message is received
Response: NSDictionary containing messages and its details

Field ‘message_type’ indicates the type of received message.
Types of messages received in this callback:

message_type = 10: For normal text messages
message_type = 11: For join chatroom invite message
message_type = 12: For image messages
message_type = 13: For handwritten messages
message_type = 14: For video messages
message_type = 17: For audio messages
message_type = 18: For file messages
message_type = 24: For bot responses

Eg:
Text message

{
    "id"= "64";
    "message"= "Hello";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 10;
}

Join Chatroom message

{
    "id"= "64";
    "message"= {
        "chatroom_id" = 23;
        "chatroom_name" = "test-ccc";
        "chatroom_password" = da39a3ee5e6b4b0d3255bfef95601890afd80709;
    };
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 11;
}

Image message

{
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=Image.png";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 12;
}

Handwritten message

{
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/handwrite/uploads/9384627441b49aad5ef6bace29cdcd36.png";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 13;
}

Video message

{
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=Video.mp4";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 14;
}

Audio message

{
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=sample.mp3";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 17;
}

File message

{
    "id"= "64";
    "message"= "http://yoursite.com/cometchat/plugins/filetransfer/download.php?      
                file=a1d28da22369e330fab64e0250226d0b.png&unencryptedfilename=sample.txt";
    "self"= 0;
    "old"= "1";
    "sent"= "1035449792;
    "from"= "73";
    "message_type" = 18;
}

Bot response

Bot response : Text
{
    "bot_id" = 33;
    "bot_response_type" = text;
    from = 98;
    id = 29;
    message = "hi this is a test message!";
    "message_type" = 24;
    old = 1;
    self = 0;
    sent = 1482401158;
}
Bot response : Image
{
    "bot_id" = 30;
    "bot_response_type" = image;
    from = 98;
    id = 31;
    message = "http://i.giphy.com/l2YWjLlllAFOkog9i.gif";
    "message_type" = 24;
    old = 1;
    self = 0;
    sent = 1482402757;
}
Bot response : Anchor
{
    "bot_id" = 33;
    "bot_response_type" = anchor;
    from = 98;
    id = 46;
    message = "hi this is a test message!<br><a href=\"https://app.bots.co/components/add/1164\">bots</a>";
    "message_type" = 24;
    old = 1;
    self = 0;
    sent = 1482403297;
}

(iv) (void(^)(NSDictionary *response))announcement
Invocation: When the admin sends a site-wide announcement
Response: NSDictionary containing the announcement message details.
Eg:

{
    "id"= "55";
    "m"="hello";
}

(v) (void(^)(NSDictionary *response))avchatMessage
Invocation: When an audio video chat message is received
Response: NSDictionary containing audio video chat messages and its details
Eg:

{
    "to"= 105;
    "id"= "64";
    "message"="AVCHAT_CALL_ACCEPTED";
    "self"= 0;
    "old"= "1";
    "sent"= 1411035449792;
    "from"= "73";
    "message_type" = 31;
}

Field ‘message_type’ indicates the type of received message.
Types of messages received in this callback:

AVCHAT_CALL_ACCEPTED
message_type = 31: Audio video call request has been accepted

AVCHAT_INCOMING_CALL
message_type = 32: Incoming audio video call request

AVCHAT_INCOMING_CALL_USER_BUSY
message_type = 33: Incoming audio video call request while user is busy

AVCHAT_END_CALL
message_type = 34: Audio video call has been ended

AVCHAT_REJECT_CALL
message_type = 35: Audio video call request has been rejected

AVCHAT_CANCEL_CALL
message_type = 36: Audio video call has been cancelled

AVCHAT_NO_ANSWER
message_type = 37: No answer received for audio video call request sent

AVCHAT_BUSY_CALL
message_type = 38: Busy call received for audio video call request sent

(vi) (void(^)(NSDictionary *response)) actionMessage
Invocation: When server sends is typing status.
Response: NSDictionary containing the current user’s is typing status.
Eg:

{
    "action":"typing_start",
    "from":"12",
    "sent":"1450849776899"
}

OR

{
    "action":"typing_stop",
    "from":"12",
    "sent":"1450849780098"
}

(vii) (void(^)(NSDictionary *response))botList
Invocation: When the server sends an updated bot’s list
Response: NSDictionary containing the bot’s list.
Eg:

{
    "_27" =     {
        a = "/cometchat/writable/bots/9GAG";
        api = aeb074769f5c4eac45137e874dd7719a91459352;
        d = "";
        id = 27;
        n = 9GAG;
    };
    "_29" =     {
        a = "/cometchat/writable/bots/Weather";
        api = 7c22b8c1a063df3009284fadc1892f692b6aa1c7;
        d = "Keywords for this bot- weather";
        id = 29;
        n = Weather;
    };
    "_30" =     {
        a = "/cometchat/writable/bots/Giphy";
        api = 07cf44c510682cf46f5fe18bc98337cea34a4caf;
        d = "";
        id = 30;
        n = Giphy;
    };
}

(viii) (void(^)(NSError *error))failure
Invocation: If there’s an error while subscribing
Response: NSError containing error code and message
Usage:

[cometchat subscribeWithMode:YES 
            onMyInfoReceived:^(NSDictionary *response) {	    
          } onGetOnlineUsers:^(NSDictionary *response) {     
         } onMessageReceived:^(NSDictionary *response){  
    } onAnnouncementReceived:^(NSDictionary *response) { 
   } onAVChatMessageReceived:^(NSDictionary *response){	
              } onGetBotList:^(NSDictionary *response) {
                    }failure:^(NSError *error) {
}];

3. Send message

Send text/emoji message to another user by specifying userID. (Ensure that userID and message must not be nil or an empty string)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When message is sent successfully.
Response: NSDictionary containing the message details.
Eg:

{
    "id"="71";
    "m"="Hi! How are you?";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending message.
Response: NSError containing error code and message.
Usage:

[cometchat sendMessage:@“Hi! How are you?” toUser:@“2” 
               success:^(NSDictionary *response) {  
             } failure:^(NSError *error) {
}];

4. Send Image

a) Send image message in the form of imageData to another user by specifying userID. (Ensure that imageData and userID should not be nil)

- (void)sendImageWithData:(NSData *)imageData 
                  toUser:(NSString *)userID
                 success:(void(^)(NSDictionary *response))response
                 failure:(void(^)(NSError *error))failure;

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When an image is sent successfully.
Response: NSDictionary containing the message id of image message and original image data.
Eg:

{
    "id"="71";
    "m"="<ffd8ffe0 00104a46 49460001 01010048 00480000 ffdb0043 00030202 02020203 02020203 03030304 06040404 04040806 
            06050609 080a0a09 0809090a 0c0f0c0a 0b0e0b09 090d110d 0e0f1010 11100a0c 12131210 130f1010 10ffdb00 430103
            03 03040304 08040408 100b090b>";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending image.
Response: NSError containing error code.
Usage:

[cometchat sendImageWithData:imageData 
                      toUser:@“2” 
                     success:^(NSDictionary *response) {  
                   } failure:^(NSError *error) {
}];

b) Send image at given imagePath to another user by specifying userID. The image file should exist at the given path location. (Ensure that nil or empty imagePath and userID should not be sent)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When an image at specified path is sent successfully.
Response: NSDictionary containing the message id of sent image message and the original image path.
Eg:

{
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/IMG1049.JPG";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending image.
Response: NSError containing error code.
Usage:

[cometchat sendImageWithPath:@“/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/IMG1049.JPG”   
                      toUser:@“2” 
                     success:^(NSDictionary *response) {  
                   } failure:^(NSError *error) {
}];

5. Audio File

Send file at given audioPath to another user by specifying userID. The audio file should exist at the given path location. (Ensure that nil or empty audioPath and userID should not be sent)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When an audio file at specified path is sent successfully.
Response: NSDictionary containing the message id of sent file message and the original file path
Eg:

{
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/sample.mp3";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending audio file
Response: NSError containing error code
Usage:

[cometchat sendAudioWithPath:@“/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/sample.mp3”   
                      toUser:@“2” 
                     success:^(NSDictionary *response) {  
                   } failure:^(NSError *error) {
}];

6. Send File

Send file at given filePath to another user by specifying userID. The file should exist at the given path location. (Ensure that nil or empty filePath and userID should not be sent)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When an file at specified path is sent successfully.
Response: NSDictionary containing the message id of sent file message and the original file path
Eg:

{
    "id"="71";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/sample.txt";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending file
Response: NSError containing error code
Usage:

[cometchat sendFileWithPath:@“/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-
                                89146DF4D1EB/Documents/sample.txt”   
                      toUser:@“2” 
                     success:^(NSDictionary *response) {  
                   } failure:^(NSError *error) {
}];

7. Send Video

a) Send video at given videoPath to the userID specified. The video file should exist at the given path location and must be in mp4 format. (Ensure that videoPath and userID should not be nil or empty)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When a video at given path is sent successfully.
Response: NSDictionary containing the message id of video message and original video path.
Eg:

{ 					
    "id"="74";
    "m"="/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB/Documents/IMG0180.mp4";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending video.
Response: NSError containing error code.
Usage:

[cometchat sendVideoWithPath:@“/var/mobile/Containers/Data/Application/F9778125-2506-4DED-9CDE-89146DF4D1EB
                                 /Documents/IMG0180.mp4” 
                      toUser:@“2” 
                     success:^(NSDictionary *response) {  
                   } failure:^(NSError *error) {
}];

b) Send video using NSURL to the userID specified. NSURL can be obtained either by accessing UIImagePickerControllerMediaURL property of a video when it is selected using UIImagePickerController or by converting path of given video to NSURL. (Ensure that videoURL and userID should not be nil or empty)

- (void)sendVideoWithURL:(NSURL *)videoURL
                  toUser:(NSString *)userID
                 success:(void(^)(NSDictionary*response))response
                 failure:(void(^)(NSError *error))failure;

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When video message is sent successfully using given videoURL.
Response: NSDictionary containing the message id of sent video message and original videoURL.
Eg:

{
    "id"="71";				 
    "m"="Users/MyPC/Desktop/72fd88e9abc28c04ef4b98d3bd62b483.3gp -- file:///”
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while sending video using given videoURL.
Response: NSError containing error code.
Usage:

[cometchat sendVideoWithURL:videoURL toUser:@“2” 
                    success:^(NSDictionary *response) {  
                  } failure:^(NSError *error) {
}];

8. Get user’s profile details

Get the profile details corresponding to the userID. This function can also be used to get logged-in user’s details. (Ensure that userID should not be nil or empty)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When the profile details corresponding to the userID is requested.
Response: NSDictionary containing the user’s profile.
Eg:

{
    "id"="5";
    "n"="a";
    "l"="";
    "a"="img.png";
    "s"="available";
    "m"="I'm available";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while performing the operation.
Response: NSError containing error code and message.
Usage:

[cometchat getUserInfo:@“5” 
               success:^(NSDictionary *response) {
             } failure:^(NSError *error) {
}];

9. Change online status

Change logged-in user’s status to ‘Available’, ‘Busy’, ‘Invisible’, ‘Offline’ by selecting a proper status value from enum STATUS_OPTIONS.

- (void)changeStatus:(NSInteger)status
             success:(void(^)(NSDictionary *response))response
             failure:(void(^)(NSError *error))failure;

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When status is updated successfully.
Response: NSDictionary containing the success message.
Eg:

{
    "Message"="Change status successful";	
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while changing user status.
Response: NSError containing error code.
Usage:

[cometchat changeStatus:STATUS_AVAILABLE
               success:^(NSDictionary *response) {  
             } failure:^(NSError *error) {
}];

10. Change status message

To change logged-in user’s status message. (Ensure that statusMessage should not be nil or empty)

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When status message is updated successfully.
Response: NSDictionary containing the success message.
Eg:

{
    "Message"="Change status message successful"
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while changing user’s status message.
Response: NSError containing error code.
Usage:

[cometchat changeStatusMessage:@“Exam Time!!”
                       success:^(NSDictionary *response) {  
                     } failure:^(NSError *error) {
}];

11. Get the list of currently active users

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When online user’s list is requested.
Response: NSDictionary containing the user’s list.
Eg:

{
    "_1" = {
        "id"="1";
        "n"="User1";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };	
    "_2" = {
        "id"="2";
        "n"="User2";
        "a"="avatar.png";
        "d"="1";
        "s"="available";
        "m"="I'm available";
    };
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while performing the operation.
Response: NSError containing error code and message.
Usage:

[cometchat getOnlineUsersWithResponse:^(NSDictionary *response) {
                            } failure:^(NSError *error) {
}];

12. Block User

To block the user corresponding to given userID. Once the user is blocked successfully, you will not be able to send/receive messages to/from the respective user.

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

Return type: void
Callback:
– (void(^)(NSDictionary *response))success;
Invocation: Triggered when block user response is received.
Response: NSDictionary containing id of blocked user.
Eg:

{
    "id"="102";
}

– (void(^)(NSError *error))failure;
Invocation: Triggered when error occurs while blocking the given user.
Response: NSError object representing error.
Usage:

[cometchat blockUser:@“102” 
             success:^(NSDictionary *response) {  
           } failure:^(NSError *error) {  
}];

13. Unblock User

To unblock user corresponding to given userID. Once the user is unblocked successfully, you will be able to send/receive messages to/from the respective user.

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

Return type: void
Callback:
– (void(^)(NSDictionary *response))response;
Invocation: Triggers when the user is successfully unblocked.
Response: NSDictionary containing id of unblocked user.
Eg:

{  
    "id"="102";
}

– (void(^)(NSError *error))failure;
Invocation: Triggers when an error occurs while unblocking given user.
Response: NSError object representing error.
Usage:

[cometchat unblockUser:@“102” 
              success:^(NSDictionary *response) {
            } failure:^(NSError *error) {
}];

14. Get list of blocked users

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When blocked user’s list is requested.
Response: NSDictionary containing the blocked user’s list.
Eg:

{
    "73"=
    {
        "id"="73";
        "name"="user73”;
    };
    "700"=
    {
        "id"="70";
        "name"="user70”;
    };
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while performing the operation.
Response: NSError containing error code and message.
Usage:

[cometchat getBlockedUsersList:^(NSDictionary *response) {
     } failure:^(NSError *error) {
}];

15. Fetch all announcements

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When announcements list is requested.
Response: NSDictionary containing the list of announcements.
Eg:

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

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while fetching the announcements list.
Response: NSError containing error code and message.
Usage:

[cometchat getAllAnnouncements:^(NSDictionary *response) {
    } failure:^(NSError *error) {
}];

16. Get chat history

To get chat history of particular user. Specify the friendID and messageID of the oldest message present in the application. The server will return messages exchanged prior to this given messageID. (Ensure that userID and messageID should not be nil or empty)

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

Parameters:
(i) friendID: The id of the user with whom you want to fetch the conversation with.
(ii) messageID: The messages fetched will be before this particular ID. If you do not have any ‘messageID’ OR you want the entire messages history, pass @”-1” to get the messages. Number of messages are set from CometChat Administration panel.

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When chat history of user is received from server.
Response: NSDictionary containing the history messages.
Eg:

{
    history = (
    {
        from = 14;
        id = 4843;
        message = rty;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429771974000;
    };
    {
        from = 14;
        id = 4844;
        message = reyrey;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429771987000;
    };
    {
        from = 14;
        id = 4845;
        message = 57457;
        "message_type" = 10;
        old = 1;
        self = 1;
        sent = 1429772014000;
    };
    {
        from = 14;
        id = 4846;
        message = 457547457457;
        "message_type" = 10;
        old = 1;
        self = 0;
        sent = 1429772019000;
    }
    );
}

(ii) (void(^)(NSError *error))failure
Invocation: If an error occurs while fetching chat history from server.
Response: NSError containing error code.
Usage:

[cometchat getChatHistoryOfUser:@“14” 
        messageID:@“4850”
        success:^(NSDictionary *response) {  
        } failure:^(NSError *error) {
}];

17. Translate Conversation

To translate ‘OneOnOne’ and ‘Chatroom’ conversations in the selected language. Refer to LANGUAGE enum for language values.

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

Return type: void
Usage:

[cometchat setTranslationlanguage:French 
      success:^(NSDictionary *response) {  
    } failure:^(NSError *error) {
}];

18. To check whether CometChat is installed at specified URL location. Return the URL of CometChat installation directory. (Ensure that siteURL nil or empty)

- (void)isCometChatInstalled:(NSString *)siteURL
              success:(void(^)(NSDictionary*response))response
              failure:(void(^)(NSError *error))failure;

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When CometChat installation directory is found at specified URL.
Response: NSDictionary containing the exact location of CometChat installation directory.
Eg:

{
    "cometchat_url"="http://www.yoursite.com/cometchat”;
}

(ii) (void(^)(NSError *error))failure
Invocation: If CometChat is not found at specified URL.
Response: NSError containing error code.
Usage:

[cometchat isCometChatInstalled:@“http://www.yoursite.com/”
      success:^(NSDictionary *response) {  
    } failure:^(NSError *error) {
}];

19. To check whether plugins are enabled or disabled.

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

Return type: void
Callback Blocks:
(i) (void(^)(NSDictionary *response))response
Invocation: When plugin information is fetched successfully.
Response: NSDictionary containing plugins with enable/disable flag.
Eg:

{
    avchat_enabled="1";
    createchatroom_enabled="1";
    blockuser_enabled="0";
    mediasharing_enabled="1";
    chatroom_mediasharing_enabled="1";
    realtime_translate_enabled="0";
}

(ii) (void(^)(NSError *error))failure
Invocation: If there’s an error while fetching plugin information.
Response: NSError containing error code.
Usage:

[cometchat  getPluginInfo:^(NSDictionary *response) {  
                } failure:^(NSError *error) {
}];

20. isTyping…
Now you can make your chat more alive by sending typing.. information to another user, so the other user will know you are typing some text to him.
Note that this feature will only work from CometChat v5.7 onwards and by using CometService.
To send a message that you are typing you need to use isTyping method. The syntax of this function is as follows:

- (void)isTyping:(BOOL)flag channel:(NSString *)channel;

Parameters:
(i) flag: This is BOOL value, pass YES when you start typing, pass NO when you stop typing.
(ii) 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.

Return type: void
Usage:


[cometChat isTyping:YES channel:buddyChannel];

OR

[cometChat isTyping:NO channel:buddyChannel];

21. To set Development Mode On/Off. If development mode is enabled (On), you can see request/response of SDK in console.

To enable Development mode pass ‘flag’ as ‘YES’.

+ (void)setDevelopmentMode:(BOOL)flag;

Return type: void
Usage:

[CometChat setDevelopmentMode:YES];

22. Check the logged-in status of the user

+ (BOOL)isLoggedIn;

Return type: BOOL

Usage:

[CometChat isLoggedIn];

23. Unsubscribe

To stop receiving OneOnOne messages, user’s list and logged-in user’s profile data.

- (void)unsubscribe;

Return type: void
Usage:

[cometchat unsubscribe];

Please refer ‎error codes for failure responses.

Not finding what you need?

The CometChat team is here to help!