logo
In-app Chat
SDK Error Codes
Powered Byspreading
On this page

Sample code

Here we provide you with a sample application to experience ZEGOCLOUD's In-app Chat, and also describe how to run the sample code.

Prepare the environment

  • React Native 0.60.0 or later
  • A real iOS device that is running on iOS 11.0 or later and supports audio and video.
  • An Android device or Simulator that is running on Android 4.1 or later and supports audio and video. We recommend you use a real device (enable the "USB Debugging" option).
  • Your device is connected to the internet.
  • Configure Visual Studio Code, search for the "React Native Tools" extension and install it.

Prerequisites

  • Go to ZEGOCLOUD Admin Console, and do the following:
    • Create a project, get the AppID and AppSign.
    • Subscribe to the In-app Chat service (contact us if the subscription doesn't go well).

For SDK 2.3.0 or later, the AppSign authentication mode and Token-based authentication mode are both supported.

If you want to change your authentication mode, please refer to the Upgrade the authentication mode from using the AppSign to Token.

Get the sample code

The following structure shows the subdirectory structure of the sample code:

Untitled
.
├── App.js
├── Gemfile
├── __tests__
├── android
├── app.json
├── babel.config.js
├── index.js
├── ios
├── main.js
├── metro.config.js
├── package-lock.json
├── package.json
├── react-native.config.js
├── src
│   ├── assets
│   │   └── js
│   │       ├── config.js
│   ├── components
│   ├── hooks
│   │   └── zim.js
│   └── pages
│       ├── action
│       ├── chat
│       ├── group
│       ├── home
│       └── login
├───────
1
Copied!

Run the sample code

  1. In Visual Studio Code, import the sample code package file.

  2. Modify the config.js file under the src/assets/js folder with the AppID and AppSign that you get in the Prerequisites steps.

    Untitled
    export const appConfig = {
        appID: , // Fill in the AppID you get. 
        appSign: , // Fill in the AppSign you get. 
    }; 
    
    1
    Copied!

    If your project uses the "Token-based authentication mode", please go to the ZEGOCLOUD Admin Console to get a temporary Token for debugging.

  3. Enter the root directory of the project, and run the yarn install to install dependencies. (for iOS devices, run the pod install command instead.)

  4. If running the program on an iOS device, please navigate to the root directory of the project and execute the command cd ios && pod install to install dependencies.

  5. In the root directory, run the yarn ios or the yarn android command to run the sample code.

Previous

Pricing

Next

Send and receive messages