Platform | Version |
React Native | v0.63.4 or later |
Android | Android Studio 3.5 or later; devices with Android 4.1 or later for apps |
iOS | Xcode 11.0 or later. Ensure that your project has a valid developer signature. |
UserID
, Key
, and UserSig
for subsequent logins.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.// npmnpm install react-native-tim-js// yarnyarn add react-native-tim-js
initSDK
to initialize the SDK and pass in your sdkAppID
.import { TencentImSDKPlugin, LogLevelEnum } from 'react-native-tim-js';const sdkAppID = 0; // Replace 0 with the SDKAppID of your Chat application when integratingconst loglevel = LogLevelEnum.V2TIM_LOG_DEBUG; // Logconst listener = {onConnecting: () => {},//...}TencentImSDKPlugin.v2TIMManager.initSDK(sdkAppID,loglevel,listener,);
TencentImSDKPlugin.v2TIMManager.login
to log in with one of the test accounts you created. If the returned `res.code` is 0, login is successful.import { TencentImSDKPlugin } from 'react-native-tim-js';const res = await TencentImSDKPlugin.v2TIMManager.login(userID: userID,userSig: userSig,);
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.createTextMessage(String)
to create a text message.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.import { TencentImSDKPlugin } from 'react-native-tim-js';const createMessage =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextMessage("The text to create");const id = createMessage.data!.id!; // The message creation IDconst res = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage({id: id, // Pass in the message creation IDreceiver: "The userID of the destination user",groupID: "The groupID of the destination group",});
sdkAppID
doesn't support sending messages to strangers. In this case, you can disable the relationship check feature in the console.nextSeq
and record its current position.import { useState } from "react";import { TencentImSDKPlugin } from "react-native-tim-js";const [nextSeq, setNextSeq] = useState<string>("0");const getConversationList = async () => {const count = 10;const res = await TencentImSDKPlugin.v2TIMManager.getConversationManager().getConversationList(count, nextSeq);setNextSeq(res.data?.nextSeq ?? "0");};
import { TencentImSDKPlugin } from "react-native-tim-js";const addConversationListener = () => {TencentImSDKPlugin.v2TIMManager.getConversationManager().addConversationListener({onNewConversation: (conversationList) => {// new conversation created callback_onConversationListChanged(conversationList);},onConversationChanged: (conversationList) => {// conversation changed callback_onConversationListChanged(conversationList);},});};
const _onConversationListChanged = (list) => {// you can use conversation list to update UI};
import { TencentImSDKPlugin } from "react-native-tim-js";const getGroupHistoryMessageList = async () => {const groupID = "";const count = 20;const lastMsgID = "";const res = await TencentImSDKPlugin.v2TIMManager.getMessageManager().getGroupHistoryMessageList(groupID, count, lastMsgID);const msgList = res.data ?? [];// here you can use msgList to render your message list};
V2TimAdvancedMsgListener.onRecvNewMessage
.onRecvNewMessage
callback is triggered, you can add new messages to the historical message list as needed.import { TencentImSDKPlugin } from "react-native-tim-js";const adVancesMsgListener = {onRecvNewMessage: (newMsg) => {_onReceiveNewMsg(newMsg);/// ... other listeners related to message},};const addAdvancedMsgListener = () => {TencentImSDKPlugin.v2TIMManager.getMessageManager().addAdvancedMsgListener(adVancesMsgListener);};
Undefined symbols for architecture x86_64 [duplicate]
is reported during demo running?
Was this page helpful?