In the Chat console, select your application and click Auxiliary Tools > UserSig Generation & Verification on the left sidebar. Enter two UserIDs and generate UserSig values, and copy the UserID, Key, and UserSig for subsequent logins.
Note:
This account is for development and testing only. Before the application is launched, the correct UserSig distribution method is to use the server to generate UserSig and provide an application-oriented API. When UserSig is needed, your application can send a request to the business server for a dynamic UserSig. For more information, see Generating UserSig.
Part 2. Integrating the SDK for React Native
Prerequisites
You have created or already have a React Native project.
Directions
Installing the Chat SDK
Run the following command to install the latest version of the Chat SDK for React Native:
// npm
npminstall react-native-tim-js
// yarn
yarnadd react-native-tim-js
Initializing the SDK
Call initSDK to initialize the SDK and pass in your sdkAppID.
In this step, you can mount some listeners to the Chat SDK, mainly including those for network status and user information change. For more information, see Interface V2TimSDKListener.Log in with a test account initially generated in the console for verification.
Logging in with a test account
Call TencentImSDKPlugin.v2TIMManager.login to log in with one of the test accounts you created. If the returned `res.code` is 0, login is successful.
const res =await TencentImSDKPlugin.v2TIMManager.login(
userID: userID,
userSig: userSig,
);
Note:
This account is for development and testing only. Before the application is launched, the correct UserSig distribution method is to integrate the calculation code of UserSig into your server and provide an application-oriented API. When UserSig is needed, your application can send a request to the business server for a dynamic UserSig. For more information, see Generating UserSig.
Sending messages
The following shows how to send a text message:
1. Call createTextMessage(String) to create a text message.
2. Get the message ID from the returned value.
3. Call sendMessage() and pass in the message ID. For receiver, you can pass in the ID of the other test account. groupID can be left empty.
const id = createMessage.data!.id!;// The message creation ID
const res =await TencentImSDKPlugin.v2TIMManager
.getMessageManager()
.sendMessage({
id: id,// Pass in the message creation ID
receiver:"The userID of the destination user",
groupID:"The groupID of the destination group",
});
Note:
If sending fails, it may be that your sdkAppID doesn't support sending messages to strangers. In this case, you can disable the relationship check feature in the console.
Obtaining the conversation list
Log in with the other test account to pull the conversation list.
The conversation list can be obtained in two ways:
1. Listen for the persistent connection callback to update the conversation list in real time.
2. Call an API to get the conversation list at certain time points.
Common use cases include:
Get the conversation list upon application start and listen for the persistent connection to update the conversation list in real time.
Requesting the conversation at certain time points
To get the conversation list, you need to maintain nextSeq and record its current position.
At this point, you have completed the Chat module development, and now users can send and receive messages and enter different conversations.
You can develop more features, such as group, user profile, relationship chain, offline push, and local search. For detailed directions, see here.
FAQs
What should I do if Undefined symbols for architecture x86_64 [duplicate] is reported during demo running?