Quick Reference - Copy-paste ready initialization and login:
I want to integrate with my app
- Get your Application Keys
- Add the CometChat Dependency
- Initialize CometChat
- Register and Login your user
- Integrate our UI Kits
I want to explore a sample app (includes UI)
Open the app folder in your favorite code editor and follow the steps mentioned in theREADME.md file.
React Native Sample App
Explore a complete React Native chat application with UI components
Get your Application Keys
Signup for CometChat and then:Add the CometChat Dependency
Install the package as an NPM module:- npm
- yarn
Async-Storage
- npm
- yarn
v2.4+ onwards, Voice & Video Calling functionality has been moved to a separate library. In case you plan to use the calling feature, please install the Calling dependency (The calling component requires some configuration. Please follow the steps mentioned in the Calling Component Configuration section below.
@cometchat/calls-sdk-react-native).Calling Component Configuration
For@cometchat/calls-sdk-react-native, please make sure you add the following additional dependencies & permissions.
Required Dependencies
Permissions
- Android
- iOS
Add the following permissions to your
AndroidManifest.xml:Platform-Specific Configuration
Android Configuration
Android Configuration
Go to the Set Minimum SDK Version:
./android folder and open the project level build.gradle file. Add all repository URLs in the repositories block under the allprojects section. Also in the same file in the buildscript section in the ext block, make sure you have set minSdkVersion to 24.Add Repository URL:iOS Configuration
iOS Configuration
Please update the minimum target version in the Podfile. Go to the Open the
./ios folder and open the Podfile. In the Podfile, update the platform version to 11.0:ios/App folder and run pod install. This will create an App.xcworkspace file. Open this and run the app.Initialize CometChat
Theinit() method initializes the settings required for CometChat. The init() method takes the below parameters:
| Parameter | Description |
|---|---|
appID | Your CometChat App ID |
appSettings | An object of the AppSettings class created using the AppSettingsBuilder class |
AppSettings class allows you to configure the following settings:
| Setting | Description |
|---|---|
| Region | The region where your app was created (mandatory) |
| Presence Subscription | Represents the subscription type for user presence (real-time online/offline status). See Presence Subscription |
| autoEstablishSocketConnection(boolean) | When set to true, the SDK manages the web-socket connection internally. When set to false, you manage the connection manually. Default: true. See Managing connections manually |
| overrideAdminHost(adminHost: string) | Uses a custom admin URL instead of the default. Used for dedicated CometChat deployments |
| overrideClientHost(clientHost: string) | Uses a custom client URL instead of the default. Used for dedicated CometChat deployments |
init() before calling any other method from CometChat. We suggest you call the init() method on app startup, preferably in the App.tsx file.
- JavaScript
- TypeScript
Register and Login your user
Once initialization is successful, you will need to create a user. To create users on the fly, you can use thecreateUser() method. This method takes a User object and the Auth Key as input parameters and returns the created User object if the request is successful.
- JavaScript
- TypeScript
Make sure that
UID and name are specified as these are mandatory fields to create a user.login() method.
We recommend you call the CometChat login() method once your user logs into your app. The login() method needs to be called only once.
- JavaScript
- TypeScript
Test Users Available: We have set up 5 users for testing with UIDs:
cometchat-uid-1, cometchat-uid-2, cometchat-uid-3, cometchat-uid-4 and cometchat-uid-5.login() method returns the User object containing all the information of the logged-in user.
Integrate our UI Kits
Please refer to the React Native UI Kit section to integrate React Native UI Kit inside your app.Best Practices
Best Practices
- Always call
init()before any other CometChat method - Call
init()on app startup (preferably inApp.tsx) - Use
getLoggedinUser()to check login state before callinglogin() - Store user credentials securely and never expose Auth Keys in client-side code for production
- Use Auth Token instead of Auth Key for production environments
Troubleshooting
Troubleshooting
- Initialization fails: Verify your App ID and Region are correct
- Login fails: Ensure the user exists or create them first using
createUser() - Network errors: Check internet connectivity and firewall settings
- Calling not working: Verify all calling dependencies are installed and permissions are granted
- iOS build fails: Run
pod installin theiosdirectory after adding dependencies