Initialization

This section provides you with the basic methods that need to be invoked to initialize CometChat.

In case you are using ionic kindly add the below statement in your typescript file after all the import statement:

declare var CCCometChat : any;

Once the above statement is done in ionic, both Cordova and ionic works in a similar way.

Please follow the steps below to get the initialization started.

Please select the product to know about the appropriate initialization steps.

Product:

In Android, Get the CometChat instance :

CCCometChat.getInstance(successcallback,failcallback);

**No need to call the getInstance Method in iOS

Initialize CometChat with the required information

In Android,

CCCometChat.initializeCometChat(siteUrl,licenseKey,apiKey,false,successcallback,failcallback);

In iOS,

CCCometChat.initializeCometChat(siteUrl,licenseKey,apiKey,"NO",successcallback,failcallback);

For Example:
In Android,

CCCometChat.initializeCometChat(siteURL, licenceKey, apiKey, false, successCallback(response){},failCallback(response){});

In iOS,

CCCometChat.initializeCometChat(siteURL, licenceKey, apiKey, "NO", successCallback(response){},failCallback(response){});

The parameters accepted by the initializeCometChat() method can be explained as follows:
siteUrl – This is the domain of your website.
licenceKey – This parameter is the product license key. You can find the license key in the CometChat members area.
apiKey – This is the API key. This can be found in the CometChat admin panel under the Settings -> Mobile tab.
successCallback – This is an instance of the Callback interface which contains the success methods.This helps you to know if the initialization was successful.
failCallback – This is an instance of the Callback interface which contains the failure methods.This helps you to know any error occurred during initialization.

In Android, Get the CometChat instance :

CCCometChat.getInstance(successcallback,failcallback);

**No need to call the getInstance Method in iOS

Initialize CometChat with the required information

In Android,

CCCometChat.initializeCometChat(siteUrl,licenseKey,apiKey,true,successcallback,failcallback);

In iOS,

CCCometChat.initializeCometChat(siteUrl,licenseKey,apiKey,"YES",successcallback,failcallback);

For Example:
In Android,

CCCometChat.initializeCometChat(siteURL, licenceKey, apiKey, true, successCallback(response){},failCallback(response){});

In iOS,

CCCometChat.initializeCometChat(siteURL, licenceKey, apiKey, "YES", successCallback(response){},failCallback(response){});

The parameters accepted by the initializeCometChat() method can be explained as follows:
siteUrl – This is the domain of your website.
licenceKey – This parameter is the product license key. You can find the license key in the CometChat members area.
apiKey – This is the API key. This can be found in the CometChat admin panel under the Settings -> Mobile tab.
successCallback – This is an instance of the Callback interface which contains the success methods.This helps you to know if the initialization was successful.
failCallback – This is an instance of the Callback interface which contains the failure methods.This helps you to know any error occurred during initialization.

Once you get the success callback you can proceed with CometChat login mechanism to authenticate the user. In case of failure you can cross check the params you passed to the initialize method and be sure that CometChat is installed on your web. To authenticate the user you will be required to use CometChat login provided in the next section.

  • Was this helpful?
  • Yes   No