Login/Logout

Login to CometChat

To start with using SDK functionality, you first need to create an instance of CometChat object

The syntax for creating the cometchat instance is as follows :

CometChat cometchat = CometChat.GetInstance (this.ApplicationContext, "");

Using CometChat Xamarin SDK you can login by 2 ways

  • Using username & password
  • The syntax for the login using username and password is as follows :

    Login(String SITE_URL,String USER_ID,"String PASSWORD", Callbacks callback);

    e.g

    cometchat.Login("http://www.yoursite.com/cometchat/","demo1","user1",new MyCallback(successObj=>this.onSucess(successObj)));

    Where MyCallback is as follows :

    class MyCallback : Java.Lang.Object, ICallback{
         Action <Org.Json.JSONObject> _onSuccess;
         Action <Org.Json.JSONObject> _onFail;
         public MyCallback(Action<Org.Json.JSONObject> onSuccess, Action<Org.Json.JSONObject> onFail = null)
          {
    	this._onFail = onFail;
    	this._onSuccess = onSuccess;
          }
          void SuccessCallbac(JSONObject){...}
          void FailCallback(JSONObject){...}
    }

    If you have logged in successfully the successCallback will be fired, containing the following response :

    {"message": "Login successful"}

  • Login as a guest user
  • To use guest login, make sure that you have enabled the guest login functionality from CometChat administration panel.
    The Syntax for the login as guest user is :

    GuestLogin(String SITE_URL, String GUEST_NAME, Callbacks callback)

    The success response will be as follows:

    {"message": "Login successful" }

    Here the id is the identification number given to the guest.

    Logout from CometChat

    Calling this function will end the current session and clears user data.
    The syntax is as follows :

    Logout(Callbacks callback)

    e.g

    cometchat.Logout(new MyCallback(successObj=>this.onSucess(successObj)));

    Not finding what you need?

    The CometChat team is here to help!