Show / Hide Table of Contents

Class V2TIMMessageManager

消息管理类

Inheritance
System.Object
V2TIMMessageManager
Namespace: com.tencent.imsdk.unity
Assembly: im-unity-plugin.dll
Syntax
public class V2TIMMessageManager : object

Methods

deleteMessageFromLocalStorage(String)

删除本地消息

该接口只能删除本地历史,消息删除后,SDK 会在本地把这条消息标记为已删除状态,getHistoryMessage 不能再拉取到,如果程序卸载重装,本地会失去对这条消息的删除标记,getHistoryMessage 还能再拉取到该条消息

Declaration
public void deleteMessageFromLocalStorage(string msgID)
Parameters
Type Name Description
System.String msgID

消息ID

deleteMessages(String[])

删除本地及云端消息

该接口会在 deleteMessageFromLocalStorage 的基础上,同步删除云端存储的消息,且无法恢复

一次最多只能删除 30 条消息,要删除的消息必须属于同一会话,一秒钟最多只能调用一次该接口

如果该账号在其他设备上拉取过这些消息,那么调用该接口删除后,这些消息仍然会保存在那些设备上,即删除消息不支持多端同步

Declaration
public void deleteMessages(string[] msgIDs)
Parameters
Type Name Description
System.String[] msgIDs

消息ID

getC2CHistoryMessageList(Int32, String, String)

获取单聊历史消息

如果 SDK 检测到没有网络,默认会直接返回本地数据

Declaration
public void getC2CHistoryMessageList(int count, string userID, string lastMsgID)
Parameters
Type Name Description
System.Int32 count

拉取消息的个数,不宜太多,会影响消息拉取的速度,这里建议一次拉取 20 个

System.String userID

用户ID

System.String lastMsgID

消息起始ID,如果传空,起始消息为会话最新消息

getGroupHistoryMessageList(Int32, String, String)

获取群历史消息

如果 SDK 检测到没有网络,默认会直接返回本地数据

只有会议群(Meeting)才能拉取到进群前的历史消息,直播群(AVChatRoom)消息不存漫游和本地数据库,调用这个接口无效
Declaration
public void getGroupHistoryMessageList(int count, string groupID, string lastMsgID)
Parameters
Type Name Description
System.Int32 count

拉取消息的个数,不宜太多,会影响消息拉取的速度,这里建议一次拉取 20 个

System.String groupID

群ID

System.String lastMsgID

消息起始ID,如果传空,起始消息为会话最新消息

insertC2CMessageToLocalStorage(String, String, String)

向C2C消息列表中添加一条消息

该接口主要用于满足向C2C聊天会话中插入一些提示性消息的需求,比如“您已成功发送消息”,这类消息有展示 在聊天消息去的需求,但并没有发送给对方的必要。 所以 insertC2CMessageToLocalStorage()相当于一个被禁用了网络发送能力的 sendMessage() 接口

通过该接口 save 的消息只存本地,程序卸载后会丢失

Declaration
public void insertC2CMessageToLocalStorage(string userID, string sender, string data)
Parameters
Type Name Description
System.String userID

用户ID

System.String sender

发送者ID

System.String data

自定义数据

insertGroupMessageToLocalStorage(String, String, String)

向群组消息列表中添加一条消息

该接口主要用于满足向群组聊天会话中插入一些提示性消息的需求,比如“您已经退出该群”,这类消息有展示 在聊天消息区的需求,但并没有发送给其他人的必要。 所以 insertGroupMessageToLocalStorage() 相当于一个被禁用了网络发送能力的 sendMessage() 接口

通过该接口 save 的消息只存本地,程序卸载后会丢失

Declaration
public void insertGroupMessageToLocalStorage(string groupID, string sender, string data)
Parameters
Type Name Description
System.String groupID

群组ID

System.String sender

发送者ID

System.String data

自定义消息

markC2CMessageAsRead(String)

设置单聊消息已读

Declaration
public void markC2CMessageAsRead(string userID)
Parameters
Type Name Description
System.String userID

用户ID

markGroupMessageAsRead(String)

设置群聊消息已读

Declaration
public void markGroupMessageAsRead(string groupID)
Parameters
Type Name Description
System.String groupID

群组ID

revokeMessage(String)

撤回消息

撤回消息的时间限制默认 2 minutes,超过 2 minutes 的消息不能撤回,您也可以在 控制台(功能配置 -> 登录与消息 -> 消息撤回设置)自定义撤回时间限制

仅支持单聊和群组中发送的普通消息,无法撤销 onlineUserOnly 为 true 即仅在线用户才能收到的消息,也无法撤销直播群(AVChatRoom)中的消息

如果发送方撤回消息,已经收到消息的一方会收到onRecvMessageRevoked 回调

Declaration
public void revokeMessage(string msgID)
Parameters
Type Name Description
System.String msgID

消息ID

sendC2CCustomMessage(String, String, Int32)

发送单聊自定义(信令)消息(最大支持 8KB)

自定义消息本质就是一端二进制 buffer,您可以在其上自由组织自己的消息格式(常用于发送信令),但是自定义消息不支持云端敏感词过滤。

Declaration
public void sendC2CCustomMessage(string customData, string userID, int sequenceID)
Parameters
Type Name Description
System.String customData

自定义消息

System.String userID

用户ID

System.Int32 sequenceID

sendC2CTextMessage(String, String, Int32)

发送单聊普通文本消息(最大支持 8KB)

文本消息支持云端的脏词过滤,如果用户发送的消息中有敏感词,失败回调将会返回 80001 错误码。

Declaration
public void sendC2CTextMessage(string text, string userID, int sequenceID)
Parameters
Type Name Description
System.String text

消息文本

System.String userID

用户ID

System.Int32 sequenceID

序列ID

sendCustomMessage(String, String, Int32, Boolean, String, Int32)

发送自定义消息

Declaration
public void sendCustomMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string data, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String data

自定义消息

System.Int32 sequenceID

sendFaceMessage(String, String, Int32, Boolean, Int32, String, Int32)

发送表情消息

Declaration
public void sendFaceMessage(string groupID, string receiver, int priority, bool onlineUserOnly, int index, string data, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.Int32 index

表情索引

System.String data

自定义数据

System.Int32 sequenceID

sendFileMessage(String, String, Int32, Boolean, String, String, Int32)

发送文件消息

Declaration
public void sendFileMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string filePath, string fileName, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String filePath

文件路径,如果是系统相册拿的图片/视频,需要先把视频导入 APP 的目录下

System.String fileName

文件名

System.Int32 sequenceID

sendGroupCustomMessage(String, String, MessagePriority, Int32)

发送群聊自定义(信令)消息(最大支持 8KB)

Declaration
public void sendGroupCustomMessage(string customData, string groupID, MessagePriority priority, int sequenceID)
Parameters
Type Name Description
System.String customData

自定义消息

System.String groupID

群ID

MessagePriority priority

设置消息的优先级,我们没有办法所有消息都能 100% 送达每一个用户,但高优先级的消息会有更高的送达成功率。

System.Int32 sequenceID

sendGroupTextMessage(String, String, MessagePriority, Int32)

发送群聊普通文本消息(最大支持 8KB)

Declaration
public void sendGroupTextMessage(string text, string groupID, MessagePriority priority, int sequenceID)
Parameters
Type Name Description
System.String text

消息文本

System.String groupID

群ID

MessagePriority priority

设置消息的优先级,我们没有办法所有消息都能 100% 送达每一个用户,但高优先级的消息会有更高的送达成功率。

System.Int32 sequenceID

sendImageMessage(String, String, Int32, Boolean, String, Int32)

发送图片消息

Declaration
public void sendImageMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string imagePath, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String imagePath

图片本地地址,如果是系统相册拿的图片/视频,需要先把视频导入 APP 的目录下

System.Int32 sequenceID

sendLocationMessage(String, String, Int32, Boolean, Double, Double, Int32)

发送地理位置消息

Declaration
public void sendLocationMessage(string groupID, string receiver, int priority, bool onlineUserOnly, double longitude, double latitude, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.Double longitude

经度

System.Double latitude

纬度

System.Int32 sequenceID

sendSoundMessage(String, String, Int32, Boolean, String, Int32, Int32)

发送语音消息

Declaration
public void sendSoundMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string soundPath, int duration, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String soundPath

语音文件地址,如果是系统相册拿的图片/视频,需要先把视频导入 APP 的目录下

System.Int32 duration

音频时长,单位秒

System.Int32 sequenceID

sendTextMessage(String, String, Int32, Boolean, String, Int32)

发送文本消息

Declaration
public void sendTextMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string text, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String text

消息文本

System.Int32 sequenceID

sendVideoMessage(String, String, Int32, Boolean, String, String, String, Int32, Int32)

发送视频消息

Declaration
public void sendVideoMessage(string groupID, string receiver, int priority, bool onlineUserOnly, string type, string videoFilePath, string snapshotPath, int duration, int sequenceID)
Parameters
Type Name Description
System.String groupID

目标群组 ID,如果是发送群聊消息,只需要指定 groupID 即可,groupID和receiver同时设置,则认定为群消息

System.String receiver

消息接收者的 userID, 如果是发送 C2C 单聊消息,只需要指定 receiver 即可,groupID和receiver同时设置,则认定为群消息

System.Int32 priority

消息优先级,仅针对群聊消息有效。请把重要消息设置为高优先级(比如红包、礼物消息),高频且不重要的消息设置为低优先级(比如点赞消息)

System.Boolean onlineUserOnly

是否只有在线用户才能收到,如果设置为 YES ,接收方历史消息拉取不到,常被用于实现”对方正在输入”或群组里的非重要提示等弱提示功能,该字段不支持 AVChatRoom

System.String type

视频类型,如 mp4 mov 等

System.String videoFilePath

视频路径,如果是系统相册拿的图片/视频,需要先把视频导入 APP 的目录下

System.String snapshotPath

视频封面文件路径,如果是系统相册拿的图片/视频,需要先把视频导入 APP 的目录下

System.Int32 duration

视频时长,单位秒

System.Int32 sequenceID
In This Article
Back to top Generated by DocFX