接收消息
开发者拦截 SDK 接收的消息,并进行相应的业务操作。
接收消息监听
通过注册消息监听代理来接收会话的新消息。
接口定义
swift
func register(messageDelegate: KIMMessageDelegate)
Objective-C
- (void)registerWithMessageDelegate:(id <KIMMessageDelegate> )messageDelegate;
参数说明
参数 | 类型 | 说明 |
---|---|---|
messageDelegate | KIMMessageDelegate | 消息事件息代理 |
KIMMessageDelegate
接收消息相关代理方法说明:
方法 | 参数 | 说明 |
---|---|---|
didReceivedMessage | message: KIMMessage 消息数据 | 接收到会话的新消息,包含从当前端发送形成本地消息及云端生成的新消息 |
didReceivedMessageStatus | chatId: String 消息所在会话id msgId: String 消息id msgStatus: KIMMsgStatus 消息状态 | 接收到消息状态更新 |
didReceivedMessageReplyInfos | chatId: String 消息所在会话id infos: [KIMMsgReplyOperation] 消息快捷回复数据 | 接收到消息快捷回复 |
KIMMsgStatus
说明:
参数 | 类型 | 说明 |
---|---|---|
total | Int32 | 总共要阅读的人数 |
unread | Int32 | 未读的人数 |
isRead | Bool | 当前用户是否已读 |
mentionReadUsers | [String] | 被 at 的用户已读列表 |
KIMMsgReplyOperation
说明:
参数 | 类型 | 说明 |
---|---|---|
msgId | String | 消息 id |
replyId | Int64 | 回复 id(emoji id) |
ctime | Int64 | emoji 的第一次被回复的时间 |
items | [KIMMsgReplyItem] | 操作内容 |
KIMMsgReplyItem
说明:
参数 | 类型 | 说明 |
---|---|---|
userId | String | 用户 id |
ctime | Int64 | 回复时间 |
replyCid | Int64 | 客户端本地 id,服务端原封不动返回 |
state | Int32 | 状态,0:撤销,1:添加 |
代码示例
swift
KIMCore.shared.register(messageDelegate: self)