集成会话消息界面
更新时间: 2025/09/11 14:15:56
本文主要介绍如何构建会话消息界面。IM UIKit 提供基于 UITableview 实现的会话消息界面,其类名为 ChatViewController,并提供了两个子类:
TeamChatViewController:群聊会话消息P2PChatViewController:单聊会话消息
IM UIKit 将会话界面拆分成 P2P 和 Team 两种类型,有利于解耦和添加用户自身的其他逻辑,在使用时,您需要注意区分会话类型。
方法原型
swiftlet p2pChatVC = P2PChatViewController(conversationId: conversationId, anchor: anchor)
let teamVC = TeamChatViewController(conversationId: conversationId, anchor: anchor)
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
| conversationId | String | 会话 ID。 |
| anchor | V2NIMMessage | 锚点,用于历史消息搜索。 |
代码示例
swift // 1、路由跳转(推荐)
if V2NIMConversationIdUtil.conversationType(conversationId) == .CONVERSATION_TYPE_P2P {
Router.shared.use(
PushP2pChatVCRouter,
parameters: ["nav": navigationController as Any,
"conversationId": conversationId as Any,
"anchor": anchor],
closure: nil
)
}else if V2NIMConversationIdUtil.conversationType(conversationId) == .CONVERSATION_TYPE_TEAM {
Router.shared.use(
PushTeamChatVCRouter,
parameters: ["nav": navigationController as Any,
"conversationId": conversationId as Any,
"anchor": anchor],
closure: nil
)
}
// 2、导航控制器跳转
if V2NIMConversationIdUtil.conversationType(conversationId) == .CONVERSATION_TYPE_P2P {
let p2pChatVC = P2PChatViewController(conversationId: conversationId, anchor: anchor)
navigationController?.pushViewController(p2pChatVC, animated: true)
}else if V2NIMConversationIdUtil.conversationType(conversationId) == .CONVERSATION_TYPE_TEAM {
let teamVC = TeamChatViewController(conversationId: conversationId, anchor: anchor)
navigationController?.pushViewController(teamVC, animated: true)
}
使用时,根据不同的会话类型,跳转到对应的界面,开源代码中内部跳转通过 Router 路由实现。路由器的具体使用说明,请参考 界面跳转。
注意事项
会话界面的部分功能需要在 网易云信控制台 开通后才能使用。具体请参考 网易云信控制台功能开通。
相关参考
- IM UIKit 会话模块支持的内置消息类型参考 基本消息类型。
- 如果需要在会话界面实现音视频通话功能,请参考 实现音视频通话功能。
- 如果需要自定义会话消息界面的 UI 样式,请参考 自定义会话消息 UI。
此文档是否对你有帮助?





