平台 | 版本 |
React Native | 0.63.4 版本以上 |
Android | Android Studio 3.5 及以上版本,App 要求 Android 4.1 及以上版本设备。 |
iOS | Xcode 11.0 及以上版本,请确保您的项目已设置有效的开发者签名。 |
UserID
、签名(Key)
、UserSig
这三个,后续登录时会用到。UserSig
签发方式是由服务器端生成,并提供面向 App 的接口,在需要 UserSig
时由 App 向业务服务器发起请求获取动态 UserSig
。更多详情请参见 服务端生成 UserSig。// npmnpm install react-native-tim-js// yarnyarn add react-native-tim-js
initSDK
,完成 SDK 初始化。将您的 sdkAppID
传入。import { TencentImSDKPlugin, LogLevelEnum } from 'react-native-tim-js';TencentImSDKPlugin.v2TIMManager.initSDK(sdkAppID: 0, // Replace 0 with the SDKAppID of your IM application when integratingloglevel: LogLevelEnum.V2TIM_LOG_DEBUG, // Loglistener: V2TimSDKListener(),);
TencentImSDKPlugin.v2TIMManager.login
方法,登录一个测试账户。当返回值res.code
为 0 时,登录成功。import { TencentImSDKPlugin } from 'react-native-tim-js';const res = await TencentImSDKPlugin.v2TIMManager.login(userID: userID,userSig: userSig,);
UserSig
签发方式是将 UserSig
的计算代码集成到您的服务端,并提供面向 App 的接口,在需要 UserSig
时由您的 App 向业务服务器发起请求获取动态 UserSig
。更多详情请参见 服务端生成 UserSig。createTextMessage(String)
创建一个文本消息。sendMessage()
发送该 ID 的消息。receiver
可填入您此前创建的另一个测试账户 ID。发送单聊消息无需填入groupID
。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 ID toreceiver: "The userID of the destination user",groupID: "The groupID of the destination group",);
nextSeq
,记录当前位置。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
回调被触发后,您可以按需将新消息添加进历史消息列表中。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]
如何解决?Failed to resolve: react-native-0.71.0-rc.0-debug
如何解决?
本页内容是否解决了您的问题?