集成消息列表界面
协作中台支持消息列表界面的集成。消息列表主要功能如下:
收发消息,包含文本消息,语音消息,图片消息,视频消息,表情,文档链接,卡片消息等。
下拉查看历史消息,历史消息来自本地缓存及云端,支持从云端拉取所有历史消息。
消息操作,包含回复消息,转发消息,消息加急,消息收藏,撤回消息等。
效果展示




可以通过两种方式集成消息列表页面:
直接使用
KIMChatMessageViewController
类,集成默认的会话列表界面。继承使用
KIMChatMessageViewController
类,通过实现协议自定义会话列表界面。
接口定义
Swift
public init(chatId: String, chatType: Int32)
Objective-c
- (instancetype)initWithChatId:(NSString *)chatId chatType:(Int32)chatType;
参数说明
参数 | 类型 | 说明 |
---|---|---|
chatId | String | 会话ID |
chatType | Int32 | 会话类型 1 单聊,2 群聊,3 机器人会话,4 文档助手 |
代码示例
- 直接使用
KIMChatMessageViewController
。
Swift
let controller = KIMChatMessageViewController(chatId: chatId, chatType: chatType)
self.navigationController.pushViewController(controller, animated: true)
Objective-c
KIMChatMessageViewController *controller = [[KIMChatMessageViewController alloc] initWithChatId:chatId chatType:chatType];
[self.navigationController pushViewController:controller animated:YES];
- 继承使用
KIMChatMessageViewController
。
Swift
// 1. 继承自会话列表视图控制器。
class CustomChatMessageViewController: KIMChatMessageViewController, KIMChatMessageViewControllerDelegate {
// 2. 重写初始化方法,设置页面自定义协议代理。
required init(chatId: String) {
super.init(chatId: chatId)
self.delegate = self
}
override func viewDidLoad() {
super.viewDidLoad()
}
// 3. 实现页面自定义协议方法。
func chatMessageViewController(_ controller: KIMChatMessageViewController, configTitleView titleView: KIMNavigationTitleView) {
// 实现标题栏配置方法完成标题栏样式自定义。
}
// ...
}
// 4. 使用自定义的视图控制器。
let controller = CustomChatMessageViewController(chatId: chatId)
self.navigationController.pushViewController(controller, animated: true)
// 5. 如果需要SDK内部全局替换成自定义的子类(如 CustomChatListViewController),可注册子类类型。
KIM.chatModule.chatMessageViewControllerType = CustomChatMessageViewController.self