TencentImSDKPlugin.v2TIMManager.getMessageManager()
中。V2TimMessage
。V2TimMessage
中可以携带不同类型子类,表示不同类型的消息。sendMessage
。public sendMessage({id,receiver,groupID,onlineUserOnly = false,isExcludedFromLastMessage = false,isExcludedFromUnreadCount = false,needReadReceipt = false,offlinePushInfo,cloudCustomData,localCustomData,priority = MessagePriorityEnum.V2TIM_PRIORITY_NORMAL,}: {id: string;receiver: string;groupID: string;onlineUserOnly?: boolean;isExcludedFromUnreadCount?: boolean;isExcludedFromLastMessage?: boolean;needReadReceipt?: boolean;offlinePushInfo?: V2TimOfflinePushInfo;cloudCustomData?: string;localCustomData?: string;priority?: MessagePriorityEnum;})
参数 | 含义 | 单聊有效 | 群聊有效 | 说明 |
id | 创建消息返回的id | YES | YES | 需要通过对应的 `createXxxMessage` 接口先行创建 |
receiver | 单聊消息接收者 userID | YES | NO | 如果是发送 C2C 单聊消息,只需要指定 receiver 即可 |
groupID | 群聊 groupID | NO | YES | 如果是发送群聊消息,只需要指定 groupID 即可 |
priority | 消息优先级 | NO | YES | 请把重要消息设置为高优先级(例如红包、礼物消息),高频且不重要的消息设置为低优先级(例如点赞消息) |
onlineUserOnly | 是否只有在线用户才能收到 | YES | YES | 如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能 |
offlinePushInfo | 离线推送信息 | YES | YES | 离线推送时携带的标题和内容 |
needReadReceipt | 发送群消息是否支持已读 | NO | YES | 发送群消息是否支持已读 |
isExcludedFromUnreadCount | 发送消息是否计入会话未读数 | YES | YES | 如果设置为 true,发送消息不会计入会话未读,默认为 false |
isExcludedFromLastMessage | 发送消息是否计入会话 lastMessage | YES | YES | 如果设置为 true,发送消息不会计入会话 lastMessage,默认为 false |
cloudCustomData | 消息云端数据 | YES | YES | 消息附带的额外的数据,存云端,消息的接受者可以访问到 |
localCustomData | 消息本地数据 | YES | YES | 消息附带的额外的数据,存本地,消息的接受者不可以访问到,App 卸载后数据丢失 |
sendMessage
。createTextMessage
(Details) 创建文本消息。sendMessage
(Details) 发送消息。import { TencentImSDKPlugin } from 'react-native-tim-js';// 创建文本消息const createTextMessage = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextMessage("test");if(createTextMessage.code == 0){String id = createTextMessage.data.id;// 发送文本消息const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "");if(sendMessageRes.code == 0){// 发送成功}}
createTextMessage
(Details) 创建文本消息。sendMessage
(Details) 发送消息。// 创建文本消息const text = "test";const atUserList = [];const createTextAtMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createTextAtMessage(text, atUserList);if(createTextAtMessageRes.code == 0){const id = createTextAtMessageRes.data.id;// 发送文本消息const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "", groupID: "groupID");if(sendMessageRes.code == 0){// 发送成功}}
sendMessage
(Details),比普通接口能设置更多的发送参数(例如优先级、离线推送信息等)。createCustomMessage
(Details) 创建自定义消息。sendMessage
(Details) 发送消息。import { TencentImSDKPlugin } from 'react-native-tim-js';// 创建自定义消息const createCustomMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createCustomMessage(data: '自定义data',desc: '自定义desc',extension: '自定义extension',);if(createCustomMessageRes.code == 0){const id = createCustomMessageRes.data.id;// 发送自定义消息const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "");if(sendMessageRes.code == 0){// 发送成功}}
createCustomMessage
(Details) 创建自定义消息。sendMessage
(Details) 发送消息。// 创建自定义消息import { TencentImSDKPlugin } from 'react-native-tim-js';// 创建自定义消息const createCustomMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createCustomMessage(data: '自定义data',desc: '自定义desc',extension: '自定义extension',);if(createCustomMessageRes.code == 0){const id = createCustomMessageRes.data.id;// 发送自定义消息const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "", groupID: "groupID");if(sendMessageRes.code == 0){// 发送成功}}
createXxxMessage
创建指定类型的富媒体消息对象,其中 Xxx 表示具体的消息类型。sendMessage
(Details) 发送消息。import { TencentImSDKPlugin } from 'react-native-tim-js';const imagePath = '本地图片绝对路径';const createImageMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().createImageMessage(imagePath);if (createImageMessageRes.code == 0) {const id = createImageMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const soundPath = '本地录音文件绝对路径';const duration = 10; // 录音时长const createSoundMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createSoundMessage(soundPath,duration// 录音时长);if (createSoundMessageRes.code == 0) {const id = createSoundMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const videoFilePath = '本地视频文件绝对路径';const type = "mp4"; // 视频类型const duration = 10; // 视频时长const snapshotPath = "本地视频封面文件绝对路径";const createVideoMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createVideoMessage(videoFilePath,type, // 视频类型duration,// 视频时长snapshotPath,);if (createVideoMessageRes.code == 0) {const id = createVideoMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const filePath = "本地文件绝对路径";const fileName = "文件名";const createFileMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createFileMessage(filePath,fileName,);if (createFileMessageRes.code == 0) {const id = createFileMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
import { TencentImSDKPlugin } from 'react-native-tim-js';const desc = "深圳市南山区深南大道"const longitude = 34;const latitude = 20;const createLocationMessage =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createLocationMessage(desc,//位置信息摘要longitude,// 经度latitude, // 纬度);if (createLocationMessage.code == 0) {const id = createLocationMessage.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
const createFaceMessageRes =await TencentImSDKPlugin.v2TIMManager.getMessageManager().createFaceMessage(0,"",);if (createFaceMessageRes.code == 0) {const id = createFaceMessageRes.data.id;const sendMessageRes = await TencentImSDKPlugin.v2TIMManager.getMessageManager().sendMessage(id: id, receiver: "userID", groupID: "groupID");if (sendMessageRes.code == 0) {// 发送成功}}
本页内容是否解决了您的问题?