Authentication

Login

This process involves logging the user into CometChat.

Product:

Login to CometChat

Login to CometChat using the userID

  (void)loginWithURL: (NSString *)url
              userid: (NSString *)userid
            observer: (UIViewController *)currentView
             success: (void (^)(NSDictionary *))success
            userinfo: (void (^)(NSDictionary *))userinfo
        chatroominfo: (void (^) (NSDictionary *))chatroominfo
    onMessageReceive: (void (^) (NSDictionary *))onMessageReceive
             failure: (void (^)(NSError *))failure;

Usage:

[msgSDK loginWithURL: @"http://yoursite.com/cometchat"
              userid: @"5" 
            observer: self 
             success: ^(NSDictionary *response){/* Code Block */}
            userinfo: ^(NSDictionary *response){/* Code Block */}
        chatroominfo: ^(NSDictionary *response){/* Code Block */}
    onMessageReceive: ^(NSDictionary *response){/* Code Block */}
             failure: ^(NSError *error){/* Code Block */}
];

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

userinfo callback:

This function will provide developer with push notification 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;
}
Login to CometChat:
Use the method loginWithUserID which accepts userid

Method Signature:

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

Callback Blocks:
i. success block: (void(^)(NSDictionary *response))response
    The success block gets invoked after successful login. The response is NSDictionary containing successful login message.
ii. failure block: (void(^)(NSError *error))failure
    The failure block gets invoked if there is any error in logging-in the user. The error is NSError containing error code and error message.

Usage:

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

Logout

Calling this function will end the current session and clears data.
Method Signature:

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

Usage:

[msgSDK logoutWithSuccess:^(NSDictionary *response) {

    }
    failure:^(NSError *error) {

    }
];
  • Was this helpful?
  • Yes   No