Ready UI

1. Add the CometChat SDK to your app:

Drag the MessageSDKFramework.framework into your Xcode project folder target. Make sure the “Copy items to destination’s group folder” checkbox is checked.

CC_1

2. Add Dependencies:

Click on Targets → Your app name → and then the ‘Build Phases’ tab.
Expand ‘Link Binary With Libraries’ as given below. And add following frameworks.

  • SystemConfigurarion.framework
  • MobileCoreServices.framework
  • CoreGraphics.framework
  • CFNetwork.framework
  • libxml2.dylib
  • libz.dylib
  • CC_2

    3. Add Linker Flag:

    Click on Targets → Your app name → and then the ‘Build Settings’ tab.
    Scroll down to the ‘Linking’ section, and double-click to the right of where it says ‘Other Linker Flags’. Click on the “+” button to add the following:

  • -ObjC
  • -all_load
  • CC_3

    CometChat allows users to converse through One-on-One Chat as well as Chatrooms

    To add Login support in your application,

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

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

    1. Initialize MessageSDK object

    MessageSDK *msgSDK =  [[MessageSDK alloc] initWithApi:@"API-Key"];

    2. Login to CometChat
    Login to CometChat by any of the 2 available methods. Please make sure that your chatlogin() function in integration.php should be configured to handle any of the login mechanisms you opt for.

    a) You can login to CometChat using the userID. All data related to the previous user will be cleared.

    - (void)loginWithID:(NSString *)username
               observer:(UIViewController *)currentView
                success:(void (^)(NSDictionary *))success
               userinfo:(void (^)(NSDictionary *))userinfo
           chatroominfo:(void (^) (NSDictionary *))chatroominfo
       onMessageReceive:(void (^) (NSDictionary *))onMessageReceive
                failure:(void (^)(NSError *))failure; 

    Return type: void
    Usage:

    [msgSDK loginWithID:@"5" observer:self success:^(NSDictionary *response) {
                  
            } userinfo:^(NSDictionary *response) {
                 
            } chatroominfo:^(NSDictionary *response) {
                  
            } onMessageReceive:^(NSDictionary *response) {
                  
            } failure:^(NSError *error) {
                  
            }];

    b) You can also login to CometChat using the username and password. All data related to the previous user will be cleared.

    - (void)loginWithUsername:(NSString *)username
                     password:(NSString *)password
                     observer:(UIViewController *)currentView
                      success:(void (^)(NSDictionary *))success
                     userinfo:(void (^)(NSDictionary *))userinfo
                 chatroominfo:(void (^) (NSDictionary *))chatroominfo
             onMessageReceive:(void (^) (NSDictionary *))onMessageReceive
                      failure:(void (^)(NSError *))failure;

    Return type: void

    Usage:

    [msgSDK loginWithUsername:"John" password:"password" observer:self success:^(NSDictionary *response) {
                 
            } userinfo:^(NSDictionary *response) {
                 
            } chatroominfo:^(NSDictionary *response) {
                
            } onMessageReceive:^(NSDictionary *response) {
                 
            } failure:^(NSError *error) {
                 
            }];

    With these callback, we have added following new functions which are as follows:

    userinfo callback : This function will provide developer with firebase channel for One-on-One Messages and Announcement messages values. The response JSON will be in following format:

    {
        "push_an_channel" = "ANN_08dd0d0d94b475e429320f76a48b06fei";
        "push_channel" = "C_339dbd60e377fbef6307320f26b93355i";
    }

    chatroominfo callback : This function will provide developer with firebase channel and other information for a chatroom when the user joins/leave the chatroom. The response JSON will be in following format:
    i] join chatroom response :

    {
        action = join;
        id = 28;
        "push_channel" = "C_555dbd60e377fbef9657320f26b45855i";
    }

    ii] leave chatroom response :

    {
        action = leave;
        id = 28;
    }
    

    onMessageReceive callback : This function will be triggered whenever the message is received in One-On-One and Chatroom. The response JSON will be in following format:
    i] One-On-One message :

    {
        "message_id" = 47;
        "user_id" = 98;
    }

    ii] Chatroom message :

    {
        "chatroom_id" = 1;
        "message_id" = 1061;
        "user_id" = 55;
    }
    

    3. Launch chat with window
    In order to open the chat with specific user, use chatWith method. The syntax for this function is as follows:

    - (void)chatWith:(NSString *)userid
       setBackButton:(BOOL)flag
            observer:(UIViewController *)currentView
             success:(void (^)(NSDictionary *))success
             failure:(void (^)(NSError *))failure;

    Note : The user name will be displayed at the status bar if the user is online.

    Return type: void

    Usage:

    [msgSDK chatWith:@"10" setBackButton:YES observer:self success:^(NSDictionary *response) {
           
        } failure:^(NSError *error) {
            
        }];

    4. Logout
    Calling this function will end the current session and clears user data

    - (void)logoutWithSuccess:(void (^)(NSDictionary *))success
                      failure:(void (^)(NSError *))failure;

    Usage:

    [msgSDK logoutWithSuccess:^(NSDictionary *response) {
            
        } failure:^(NSError *error) {
            
        }];

    Not finding what you need?

    The CometChat team is here to help!