Authentication

Login

This section provides you with the required information regarding the user authentication mechanism.

The below mentioned methods need to be used to login the user. Please follow the steps below to login the user into CometChat.

Product:
Using the CometChat object created during the initialization phase, call the login method below:

Method Signature:

- (void)login:(NSString *)username
     password:(NSString *)password
      success:(void (^)(NSDictionary *response))success
      failure:(void (^)(NSError *error))failure;

The parameters needed for the login method are as follows:
username – Username of the user.
password – Password for the user.
callback – This is an instance of the Callback interface which contains the success and failure methods.This helps you to know if the login attempt was successful. Usage:

    [cometChat login:@"user1" password:@"password123" success:^(NSDictionary *response) {

    } failure:^(NSError *error) {

    }];

The initialization steps remain the same for the cloud variant. The login mechanism uses just the userId of the user instead of the username and password. Use the CometChat object created during the initialization, and call the login method below Method Signature:

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

Parameters
userId – User ID of the user.
callback – This is an instance of the Callback interface which contains the success and failure methods.This helps you to know if the login attempt was successful. Usage:

[cometChat login:@"10" success:^(NSDictionary *response) {

    } failure:^(NSError *error) {

    }];

Logout

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

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

Callback Interface: The callback interface contains the methods successCallback and failCallback. The method successCallback triggers with successful logout and contains “logout successful” message in JSON object. The method failCallback triggers with unsuccessful logout and contains error information in JSON object. Usage:

    [cometChat logout:^(NSDictionary *response) {

    } failure:^(NSError *error) {

    }];

  • Was this helpful?
  • Yes   No