IMPClient 类(iOS IMLib)

类继承图​

Object→IMPClient

继承关系:Object → IMPClient。初始化方法为 SDK 唯一入口;实例由初始化接口返回,不直接 new。

类说明​

IMPClient 是 iOS IMLib 的入口类:持有连接与事件总线,串联连接、消息、会话、用户、好友、群组、聊天室与文件上传共 62 个语义操作。方法名与 IDL 语义 op 同名,仅调用风格与常量名随平台变化。

项值
程序包ImpIaaSIM
完整声明ImpIaaSIM(Swift Package)
语言 / 运行时Swift 5.9
初始化入口ImpIaaSIM.client(options: IMPClientOptions) -> IMPClient
异步模型async -> RcResult<T>(不 throw;错误码在 RcResult.code,返回 null 的 op 用 RcResult<Void>)
事件 APIaddEventListener(_ event: IMPEvent, listener: IMPEventListener) / removeEventListener(_ event:listener:)
命名约定camelCase,方法名与语义 op 同名(camelCase 原样);init 由工厂 ImpIaaSIM.client(options:) 表达
方法总数103 个语义操作,本平台导出 103 个
平台状态已交付

概要​

方法按能力域分组。点击方法名跳转到详细说明;"签名"列逐字来自平台绑定的 methodMap。

连接与监听(7)​

方法签名(本平台绑定)说明
initstatic func client(options: IMPClientOptions) -> IMPClient初始化 SDK(构造客户端实例)
connectfunc connect(token: String) async -> RcResult<IMPConnectResult>使用用户 token 建立长连接:握手→hello→离线补发→sync_done
disconnectfunc disconnect() async -> RcResult<Void>主动断开
getConnectionStatusfunc getConnectionStatus() -> IMPConnectionStatus返回 ConnectionStatus 枚举值
getCurrentUserIdfunc getCurrentUserId() -> String当前登录 userId
addEventListenerfunc addEventListener(_ event: IMPEvent, listener: IMPEventListener) -> Void注册事件监听
removeEventListenerfunc removeEventListener(_ event: IMPEvent, listener: IMPEventListener) -> Void移除事件监听

功能指南:建立连接、连接监听

消息(26)​

方法签名(本平台绑定)说明
sendMessagefunc sendMessage(conversationType: IMPConversationType, targetId: String, content: IMPMessageContent, options:…发送任意类型消息
sendTextMessagefunc sendTextMessage(conversationType: IMPConversationType, targetId: String, text: String, options: IMPTextSe…发送文本消息
sendImageMessagefunc sendImageMessage(conversationType: IMPConversationType, targetId: String, content: IMPImageContent, optio…发送图片消息
sendFileMessagefunc sendFileMessage(conversationType: IMPConversationType, targetId: String, content: IMPFileContent, options…发送文件消息
sendVoiceMessagefunc sendVoiceMessage(conversationType: IMPConversationType, targetId: String, content: IMPVoiceContent, optio…发送语音消息
sendLocationMessagefunc sendLocationMessage(conversationType: IMPConversationType, targetId: String, content: IMPLocationContent,…发送位置消息
sendTypingStatusfunc sendTypingStatus(conversationType: IMPConversationType, targetId: String, typing: Bool) async -> RcResult…发送正在输入状态
recallMessagefunc recallMessage(messageId: String) async -> RcResult<IMPMessage>撤回消息(仅发送者、撤回时限内)
sendReadReceiptfunc sendReadReceipt(conversationType: IMPConversationType, targetId: String, messageIds: [String]) async -> R…上报已读回执
getMessageReadCountfunc getMessageReadCount(messageId: String) async -> RcResult<IMPMessageReadCount>查询消息已读人数
getMessageReadUsersfunc getMessageReadUsers(messageId: String, options: IMPPageOptions?) async -> RcResult<IMPMessageReadUsers>查询已读用户明细(分页)
getMessageReadDetailfunc getMessageReadDetail(messageId: String, options: IMPPageOptions?) async -> RcResult<IMPMessageReadDetail>查询单条消息的已读详情:已读/未读名单 + 具体读取时间(分页)
searchMessagesfunc searchMessages(options: IMPSearchMessagesOptions) async -> RcResult<IMPMessageSearchResult>在当前用户全部会话中搜索文本消息(倒序)
updateMessageExpansionfunc updateMessageExpansion(messageId: String, expansion: [String: String]) async -> RcResult<IMPExpansion>更新已发送消息的扩展 KV(合并语义)
removeMessageExpansionfunc removeMessageExpansion(messageId: String, keys: [String]) async -> RcResult<IMPExpansion>删除消息扩展 KV(按 key)
addMessageReactionfunc addMessageReaction(_ param: IMPUpdateMessageReactionParam) async -> RcResult<IMPMessageReaction>为指定消息添加回应(reactionId 由业务定义,1-16 字符)
removeMessageReactionfunc removeMessageReaction(_ param: IMPUpdateMessageReactionParam) async -> RcResult<IMPReactionRemoval>移除自己对指定消息的回应
batchGetMessageReactionSummariesfunc batchGetMessageReactionSummaries(_ param: IMPMessageReactionSummaryQuery) async -> RcResult<[String: [IMP…批量查询消息回应摘要(1-100 个 messageId)
getMessageReactionsfunc getMessageReactions(_ param: IMPGetMessageReactionsParam) async -> RcResult<IMPMessageReactionPage>分页查询指定消息的回应列表(count 1-50,默认 20)
getMessageReactionUsersfunc getMessageReactionUsers(_ param: IMPGetMessageReactionUsersParam) async -> RcResult<IMPMessageReactionUse…分页查询某个回应的参与用户(count 1-50,默认 20)
startStreamMessagefunc startStreamMessage(_ param: IMPStartStreamMessageParam) async -> RcResult<IMPStreamMessage>开始一条流式消息(IDL rev17)
appendStreamMessagefunc appendStreamMessage(streamId: String, delta: String, seq: UInt32?) async -> RcResult<IMPStreamMessage>追加一个流式增量(IDL rev17)
completeStreamMessagefunc completeStreamMessage(streamId: String) async -> RcResult<IMPStreamCompleteResult>结束流式消息(IDL rev17)
getStreamMessagefunc getStreamMessage(streamId: String) async -> RcResult<IMPStreamMessage>查询流式消息快照(IDL rev17)
getMessageExpansionfunc getMessageExpansion(messageId: String) async -> RcResult<IMPMessageExpansion>读取已发送消息的扩展 KV(IDL rev19)
combineMessagesfunc combineMessages(_ messages: [IMPMessage], options: IMPCombineMessagesOptions?) -> RcResult<IMPCombineCont…本地构造合并转发内容(IDL rev19,transport=local,不做网络 IO):把 Message[] 转换为 `{type:'co…

功能指南:发送消息、接收消息、消息管理、已读回执、输入状态、消息进阶

会话(22)​

方法签名(本平台绑定)说明
getConversationListfunc getConversationList() async -> RcResult<[IMPConversation]>会话列表:置顶优先、按 updatedAt 倒序
getConversationfunc getConversation(conversationType: IMPConversationType, targetId: String) async -> RcResult<IMPConversatio…单会话详情
getHistoryMessagesfunc getHistoryMessages(conversationType: IMPConversationType, targetId: String, options: IMPHistoryOptions?) …历史消息分页(beforeSeq 向前翻页)
clearUnreadCountfunc clearUnreadCount(conversationType: IMPConversationType, targetId: String) async -> RcResult<Void>清空会话未读(等价 read 帧 + 本地清零)
setConversationToTopfunc setConversationToTop(conversationType: IMPConversationType, targetId: String, isTop: Bool) async -> RcRes…会话置顶/取消
saveTextMessageDraftfunc saveTextMessageDraft(conversationType: IMPConversationType, targetId: String, draft: String) async -> RcR…保存草稿(空串=清除)
getTextMessageDraftfunc getTextMessageDraft(conversationType: IMPConversationType, targetId: String) async -> RcResult<String>读取草稿
clearTextMessageDraftfunc clearTextMessageDraft(conversationType: IMPConversationType, targetId: String) async -> RcResult<Void>清除草稿
setConversationNotificationLevelfunc setConversationNotificationLevel(conversationType: IMPConversationType, targetId: String, level: IMPNotif…会话提醒级别:0 全部 / 1 仅提及 / 2 免打扰
createConversationTagfunc createConversationTag(_ param: IMPCreateConversationTagParam) async -> RcResult<IMPConversationTag>创建会话标签(tagName ≤16)
updateConversationTagfunc updateConversationTag(_ param: IMPUpdateConversationTagParam) async -> RcResult<IMPConversationTag>重命名会话标签
deleteConversationTagfunc deleteConversationTag(tagId: String) async -> RcResult<Void>删除会话标签(同时清除标签内会话引用)
getConversationTagsfunc getConversationTags() async -> RcResult<[IMPConversationTag]>获取全部会话标签(含会话数量)
addConversationsToTagfunc addConversationsToTag(_ param: IMPTagConversationsParam) async -> RcResult<IMPConversationTagMembershipRe…把会话加入标签(≤100/次,幂等)
removeConversationsFromTagfunc removeConversationsFromTag(_ param: IMPTagConversationsParam) async -> RcResult<IMPConversationTagMembers…把会话移出标签(≤100/次,幂等)
getConversationsFromTagByPagefunc getConversationsFromTagByPage(_ param: IMPTagConversationsPageParam) async -> RcResult<IMPConversationTag…分页获取标签内会话(含置顶/未读数/最后消息时间)
getTagsFromConversationfunc getTagsFromConversation(conversationType: Int, targetId: String) async -> RcResult<[IMPConversationTag]>查询某个会话所属的标签列表
getUnreadCountByTagfunc getUnreadCountByTag(tagId: String) async -> RcResult<IMPConversationTagUnread>标签内未读汇总(消息总数 + 有未读的会话数)
setConversationToTopInTagfunc setConversationToTopInTag(_ param: IMPTagTopParam) async -> RcResult<Void>标签内置顶/取消置顶会话(同步会话会话级置顶状态)
deleteConversationfunc deleteConversation(conversationType: Int, targetId: String) async -> RcResult<Bool>删除会话记录(列表项/未读/草稿/置顶),历史消息保留
getConversationTypeNotificationfunc getConversationTypeNotification(conversationType: Int) async -> RcResult<IMPConversationTypeNotification>查询按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)
setConversationTypeNotificationfunc setConversationTypeNotification(conversationType: Int, level: Int) async -> RcResult<IMPConversationTypeN…设置按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)

功能指南:历史消息、会话列表、未读数、草稿、置顶与免打扰、会话标签与分组、会话删除与类型免打扰

用户(10)​

方法签名(本平台绑定)说明
getUserProfilefunc getUserProfile(userId: String) async -> RcResult<IMPUserProfile>查询用户资料
updateMyUserProfilefunc updateMyUserProfile(profile: IMPUserProfileUpdate) async -> RcResult<IMPUserProfile>修改本人资料(name/avatarUrl)
getOnlineStatusfunc getOnlineStatus(userId: String) async -> RcResult<IMPUserOnlineStatus>查询单个用户在线状态
getOnlineStatusBatchfunc getOnlineStatusBatch(userIds: [String]) async -> RcResult<IMPUserOnlineStatusBatch>批量在线状态(<=100)
subscribePresencefunc subscribePresence(userIds: [String]) async -> RcResult<IMPPresenceSubscription>订阅用户在线状态(IDL rev20)
unsubscribePresencefunc unsubscribePresence(userIds: [String]) async -> RcResult<IMPPresenceSubscription>取消订阅用户在线状态(IDL rev20)
getPresenceSubscriptionsfunc getPresenceSubscriptions() async -> RcResult<IMPPresenceSubscription>查询当前用户的在线状态订阅列表(IDL rev20)
registerPushTokenfunc registerPushToken(options: IMPRegisterPushTokenOptions) async -> RcResult<IMPPushToken>注册设备推送 token(IDL rev21 C23 收口)
unregisterPushTokenfunc unregisterPushToken(tokenId: String) async -> RcResult<IMPUnregisterPushTokenResult>注销本人设备推送 token(IDL rev21 C23)
getPushTokensfunc getPushTokens() async -> RcResult<IMPPushTokenListResult>查询本人设备推送 token(IDL rev21 C23)

功能指南:用户资料、在线状态、在线状态订阅与推送令牌

好友与黑名单(11)​

方法签名(本平台绑定)说明
searchUsersfunc searchUsers(keyword: String, options: IMPPageOptions?) async -> RcResult<IMPUserSearchResult>搜索用户(userId/name,大小写不敏感,排除自己)
sendFriendRequestfunc sendFriendRequest(toUserId: String, message: String?) async -> RcResult<IMPFriendRequest>发起好友申请
getFriendRequestsfunc getFriendRequests(options: IMPFriendRequestQuery?) async -> RcResult<[IMPFriendRequest]>好友申请列表(incoming/outgoing,pending/all)
acceptFriendRequestfunc acceptFriendRequest(requestId: String) async -> RcResult<IMPFriendRequest>同意申请,双向建立好友关系
rejectFriendRequestfunc rejectFriendRequest(requestId: String) async -> RcResult<IMPFriendRequest>拒绝申请
getFriendsfunc getFriends() async -> RcResult<[IMPFriend]>好友列表(含备注/在线/拉黑标记)
deleteFriendfunc deleteFriend(friendId: String) async -> RcResult<Void>双向删除好友
setFriendRemarkfunc setFriendRemark(friendId: String, remark: String) async -> RcResult<Void>设置好友备注(<=64 字,空串清除)
getBlacklistfunc getBlacklist() async -> RcResult<[IMPBlacklistEntry]>黑名单列表
addToBlacklistfunc addToBlacklist(userId: String) async -> RcResult<Void>加入黑名单(幂等)
removeFromBlacklistfunc removeFromBlacklist(userId: String) async -> RcResult<Void>移出黑名单

功能指南:好友列表、好友请求、黑名单

群组(20)​

方法签名(本平台绑定)说明
createGroupfunc createGroup(_ options: IMPCreateGroupOptions) async -> RcResult<IMPGroup>创建群(groupType 缺省 normal)
getGroupsInfofunc getGroupsInfo(groupIds: [String]) async -> RcResult<[IMPGroup]>批量查询群信息(<=20)
getGroupMembersfunc getGroupMembers(groupId: String) async -> RcResult<[IMPGroupMember]>群成员列表(含角色/禁言)
addGroupMembersfunc addGroupMembers(groupId: String, userIds: [String]) async -> RcResult<IMPAddGroupMembersResult>拉人入群(群主/管理员)
removeGroupMembersfunc removeGroupMembers(groupId: String, userIds: [String]) async -> RcResult<IMPRemoveGroupMembersResult>移除成员(群主/管理员)
quitGroupfunc quitGroup(groupId: String) async -> RcResult<Void>退出群
updateGroupNamefunc updateGroupName(groupId: String, name: String) async -> RcResult<IMPGroup>修改群名(群主/管理员)
updateGroupNoticefunc updateGroupNotice(groupId: String, notice: String) async -> RcResult<IMPGroup>设置群公告(群主/管理员,<=500 字,空串清除)
transferGroupOwnerfunc transferGroupOwner(groupId: String, newOwner: String) async -> RcResult<IMPGroup>转让群主(新群主须为成员)
addGroupAdminfunc addGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>设置管理员(群主,幂等)
removeGroupAdminfunc removeGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>取消管理员(群主)
muteGroupMemberfunc muteGroupMember(groupId: String, userId: String, mutedUntil: UInt64) async -> RcResult<IMPMuteGroupMember…禁言/解禁(群主/管理员)
createSupergroupChannelfunc createSupergroupChannel(params: IMPCreateSupergroupChannelParams) async -> RcResult<IMPSupergroupChannel>创建超级群频道(IDL rev21 C17)
listSupergroupChannelsfunc listSupergroupChannels(groupId: String) async -> RcResult<IMPSupergroupChannelListResult>超级群频道列表(IDL rev21 C17)
joinSupergroupChannelfunc joinSupergroupChannel(channelId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPJoin…加入超级群频道(IDL rev21 C17)
leaveSupergroupChannelfunc leaveSupergroupChannel(channelId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPLea…离开超级群频道(IDL rev21 C17)
bindUserGroupToChannelfunc bindUserGroupToChannel(channelId: String, userGroupId: String, options: IMPSupergroupChannelOptions?) asy…把用户组绑定到频道(IDL rev21 C17)
createUserGroupfunc createUserGroup(params: IMPCreateUserGroupParams) async -> RcResult<IMPUserGroup>创建超级群用户组(IDL rev21 C17)
listUserGroupsfunc listUserGroups(groupId: String) async -> RcResult<IMPUserGroupListResult>超级群用户组列表(IDL rev21 C17)
getUserGroupsByUserfunc getUserGroupsByUser(userId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPUserGroup…查询某用户所在的所有用户组(IDL rev21 C17)

功能指南:创建群组、群成员、群管理、超级群频道与用户组

聊天室(5)​

方法签名(本平台绑定)说明
createChatroomfunc createChatroom(options: IMPCreateChatroomOptions) async -> RcResult<IMPChatroom>创建聊天室(客户端能力)
joinChatroomfunc joinChatroom(chatroomId: String) async -> RcResult<IMPChatroom>加入聊天室:发送 chatroom_join,收到 chatroom_joined
leaveChatroomfunc leaveChatroom(chatroomId: String) async -> RcResult<Void>离开聊天室
getChatroomInfofunc getChatroomInfo(chatroomId: String) async -> RcResult<IMPChatroom>聊天室信息(含在线数)
getChatroomMembersfunc getChatroomMembers(chatroomId: String, options: IMPPageOptions?) async -> RcResult<IMPChatroomMembersPage…聊天室在线成员列表

功能指南:加入与退出、聊天室信息

系统通知(1)​

方法签名(本平台绑定)说明
getSystemMessagesfunc getSystemMessages(options: IMPHistoryOptions?) async -> RcResult<IMPHistoryPage>系统通知历史(会话 conversationType=SYSTEM,targetId='system')

功能指南:系统通知

文件上传(1)​

方法签名(本平台绑定)说明
uploadFilefunc uploadFile(data: Data, name: String, mime: String?) async -> RcResult<IMPUploadResult>上传文件(<=20MB),返回可用于图片/文件/语音消息的 url

功能指南:文件上传

详细成员说明​

连接与监听(7)​

static func client(options: IMPClientOptions) -> IMPClient
自 1.0.0本地(无 IO)幂等

初始化 SDK(构造客户端实例)。幂等:同 appkey 重复初始化返回同一实例。 可能错误码:1001 参数错误。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
options{appkey:string, serverUrl?:string, timeoutMs?:uint32, transport?:any}可选参数对象
返回

IMClient 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let client = ImpIaaSIM.client(options: options)
func connect(token: String) async -> RcResult<IMPConnectResult>
自 1.0.0长连接(WebSocket)

使用用户 token 建立长连接:握手→hello→离线补发→sync_done;成功后触发 CONNECTED。失败按协议重连策略重试。 可能错误码:1002 Token 无效或已过期、1016 账号已被封禁、1017 应用已停用、2001 服务端内部错误、2002 依赖服务不可用、3002 请求超时、3003 网络错误。 可能触发事件:CONNECTING、CONNECTED。

参数
参数类型说明
tokenstring见类型定义
返回

{userId:string, sessionId?:string} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.connect(token: "<user-token>")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func disconnect() async -> RcResult<Void>
自 1.0.0长连接(WebSocket)幂等

主动断开;停止重连、清理心跳与待决请求。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.disconnect()
func getConnectionStatus() -> IMPConnectionStatus
自 1.0.0本地(无 IO)

返回 ConnectionStatus 枚举值。 可能错误码:无特定错误码(通用错误见 ErrorCode)。

返回

ConnectionStatus 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let value = client.getConnectionStatus()
print(value)
func getCurrentUserId() -> String
自 1.0.0本地(无 IO)

当前登录 userId;未登录返回空串。 可能错误码:无特定错误码(通用错误见 ErrorCode)。

返回

string 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let value = client.getCurrentUserId()
print(value)
func addEventListener(_ event: IMPEvent, listener: IMPEventListener) -> Void
自 1.0.0本地(无 IO)幂等

注册事件监听;同一 handler 重复注册只生效一次。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
eventstring事件名,取值见 EventType
handlerfunction事件处理函数(注册与移除需传同一引用)
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
let listener = EventListener() // 实现 IMPEventListener
client.addEventListener(.messages, listener: listener)
func removeEventListener(_ event: IMPEvent, listener: IMPEventListener) -> Void
自 1.0.0本地(无 IO)幂等

移除事件监听。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
eventstring事件名,取值见 EventType
handlerfunction事件处理函数(注册与移除需传同一引用)
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
client.removeEventListener(.messages, listener: listener)

消息(26)​

func sendMessage(conversationType: IMPConversationType, targetId: String, content: IMPMessageContent, options: IMPSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送任意类型消息。优先走长连接;连接不可用(SUSPEND/DISCONNECTED)时按 SDK_NO_CONNECTION 失败并保留本地待发队列(可选实现)。rev23:options.channelId 用于超级群频道消息(conversationType=10),仅频道成员接收;消息模型带 channelId。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在、1006 未加入群组、1007 消息体过大(上限 5KB)、1008 发送过于频繁、1009 你已被禁言、1010 内容包含敏感词、1011 已被对方拉黑或你已拉黑对方 等 17 个。 可能触发事件:MESSAGES、CONVERSATION。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
contentContent消息内容体,字段见 MessageContent
options{clientMsgId?:string, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendMessage(conversationType: .privateChat, targetId: "user_001", content: .text(IMPTextContent(text: "Hello, NI PaaS!")), options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendTextMessage(conversationType: IMPConversationType, targetId: String, text: String, options: IMPTextSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送文本消息;内部等价 sendMessage(content={type:'text',text,mentionedInfo?,quote?})。 可能错误码:1001 参数错误、1007 消息体过大(上限 5KB)、1009 你已被禁言、1010 内容包含敏感词、1011 已被对方拉黑或你已拉黑对方、3001 长连接未就绪、3002 请求超时。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
textstring文本消息内容(非空,序列化后 ≤ 5KB)
options{clientMsgId?:string, mentionedInfo?:MentionedInfo, quote?:Quote, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendTextMessage(conversationType: .privateChat, targetId: "user_001", text: "Hello, NI PaaS!", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendImageMessage(conversationType: IMPConversationType, targetId: String, content: IMPImageContent, options: IMPSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送图片消息;url 由 uploadFile 或业务方上传得到。 可能错误码:1001 参数错误、1007 消息体过大(上限 5KB)、1009 你已被禁言、1011 已被对方拉黑或你已拉黑对方、3001 长连接未就绪。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
content{url:string,width?:uint32,height?:uint32,size?:uint64}消息内容体,字段见 MessageContent
options{clientMsgId?:string, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendImageMessage(conversationType: .privateChat, targetId: "user_001", content: IMPImageContent(url: "value"), options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendFileMessage(conversationType: IMPConversationType, targetId: String, content: IMPFileContent, options: IMPSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送文件消息。 可能错误码:1001 参数错误、1007 消息体过大(上限 5KB)、1009 你已被禁言、1011 已被对方拉黑或你已拉黑对方、3001 长连接未就绪。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
content{url:string,name:string,size?:uint64,mime?:string}消息内容体,字段见 MessageContent
options{clientMsgId?:string, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendFileMessage(conversationType: .privateChat, targetId: "user_001", content: IMPFileContent(url: "value", name: "sample.png"), options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendVoiceMessage(conversationType: IMPConversationType, targetId: String, content: IMPVoiceContent, options: IMPSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送语音消息;duration 秒 1..300。 可能错误码:1001 参数错误、1007 消息体过大(上限 5KB)、1009 你已被禁言、1011 已被对方拉黑或你已拉黑对方、3001 长连接未就绪。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
content{url:string,duration:uint32}消息内容体,字段见 MessageContent
options{clientMsgId?:string, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendVoiceMessage(conversationType: .privateChat, targetId: "user_001", content: IMPVoiceContent(url: "value", duration: 1), options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendLocationMessage(conversationType: IMPConversationType, targetId: String, content: IMPLocationContent, options: IMPSendOptions?) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

发送位置消息;lat/lng 范围校验。 可能错误码:1001 参数错误、1007 消息体过大(上限 5KB)、1009 你已被禁言、1011 已被对方拉黑或你已拉黑对方、3001 长连接未就绪。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
content{latitude:double,longitude:double,address?:string}消息内容体,字段见 MessageContent
options{clientMsgId?:string, channelId?:string}可选参数对象(可选)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendLocationMessage(conversationType: .privateChat, targetId: "user_001", content: IMPLocationContent(latitude: 1.0, longitude: 1.0), options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendTypingStatus(conversationType: IMPConversationType, targetId: String, typing: Bool) async -> RcResult<Void>
自 1.0.0长连接(WebSocket)

发送正在输入状态;不持久化;对端触发 TYPING 事件。 可能错误码:1004 用户不存在、1005 群组不存在、1006 未加入群组、1008 发送过于频繁、3001 长连接未就绪。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
typingbooltrue=正在输入,false=停止输入
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.sendTypingStatus(conversationType: .privateChat, targetId: "user_001", typing: true)
func recallMessage(messageId: String) async -> RcResult<IMPMessage>
自 1.0.0长连接(WebSocket)

撤回消息(仅发送者、撤回时限内)。成功后本地与对端收到 MESSAGE_RECALLED。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1022 超过撤回时限、1023 消息已撤回、3001 长连接未就绪。 可能触发事件:MESSAGE_RECALLED、CONVERSATION。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
返回

Message 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.recallMessage(messageId: "msg_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendReadReceipt(conversationType: IMPConversationType, targetId: String, messageIds: [String]) async -> RcResult<IMPSendReadReceiptResult>
自 1.0.0长连接(WebSocket)

上报已读回执;服务端记录唯一读者并推送给消息发送者。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、3001 长连接未就绪。 可能触发事件:READ_RECEIPT。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdsstring[]消息 ID 列表
返回

{messageIds:string[], readCounts?:map<string,uint32>, totalMembers?:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendReadReceipt(conversationType: .privateChat, targetId: "user_001", messageIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageReadCount(messageId: String) async -> RcResult<IMPMessageReadCount>
自 1.0.0REST(HTTP)

查询消息已读人数。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
返回

{messageId:string, readCount:uint32, totalMembers:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageReadCount(messageId: "msg_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageReadUsers(messageId: String, options: IMPPageOptions?) async -> RcResult<IMPMessageReadUsers>
自 1.0.0REST(HTTP)

查询已读用户明细(分页)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
options{offset?:uint32, limit?:uint32}可选参数对象(可选)
返回

{messageId:string, readCount:uint32, totalMembers:uint32, readers:UserProfile[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageReadUsers(messageId: "msg_001", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageReadDetail(messageId: String, options: IMPPageOptions?) async -> RcResult<IMPMessageReadDetail>
自 1.7.0REST(HTTP)

查询单条消息的已读详情:已读/未读名单 + 具体读取时间(分页;filter=all|read|unread,默认 all)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
options{offset?:uint32, limit?:uint32, filter?:string}可选参数对象(可选)
返回

{messageId:string, readCount:uint32, unreadCount:uint32, totalMembers:uint32, filter:string, offset:uint32, limit:uint32, total:uint32, hasMore:boolean, items:MessageReadDetailItem[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageReadDetail(messageId: "msg_001", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func searchMessages(options: IMPSearchMessagesOptions) async -> RcResult<IMPMessageSearchResult>
自 1.0.0REST(HTTP)

在当前用户全部会话中搜索文本消息(倒序)。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
options{keyword:string, limit?:uint32}可选参数对象
返回

{messages:Message[], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.searchMessages(options: IMPSearchMessagesOptions(keyword: "ni"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func updateMessageExpansion(messageId: String, expansion: [String: String]) async -> RcResult<IMPExpansion>
自 1.1.0REST(HTTP)

更新已发送消息的扩展 KV(合并语义)。仅单聊/群聊/超级群支持,且消息须在发送时开启可扩展;单次 ≤20 对、单条 ≤300 对,key 1-32 字符 [A-Za-z0-9+=_-]、value ≤4096。 可能错误码:1001 参数错误、1004 用户不存在、1026 消息不可扩展(发送时未开启可扩展,或会话类型不支持)、1027 消息扩展超出限制(单次 20 对 / 单条 300 对 / 键值长度)。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
expansionRecord<string,string>见类型定义
返回

{messageId:string, expansion:Record<string,string>} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.updateMessageExpansion(messageId: "msg_001", expansion: ["k1": "v1"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func removeMessageExpansion(messageId: String, keys: [String]) async -> RcResult<IMPExpansion>
自 1.1.0REST(HTTP)

删除消息扩展 KV(按 key)。语义与融云 removeMessageExpansion 对齐:消息须可扩展,删除不存在的 key 不报错。 可能错误码:1001 参数错误、1004 用户不存在、1026 消息不可扩展(发送时未开启可扩展,或会话类型不支持)。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
keysstring[]见类型定义
返回

{messageId:string, removed:string[], expansion:Record<string,string>} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.removeMessageExpansion(messageId: "msg_001", keys: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func addMessageReaction(_ param: IMPUpdateMessageReactionParam) async -> RcResult<IMPMessageReaction>
自 1.1.0REST(HTTP)

为指定消息添加回应(reactionId 由业务定义,1-16 字符;同一用户对同一消息同一 reactionId 重复添加视为幂等)。单条消息最多 50 种回应、每种回应最多 100 个用户。 可能错误码:1001 参数错误、1004 用户不存在、1028 回应标识非法(1-16 字符)、1029 单条消息回应种类超出上限(50)、1030 单个回应参与用户超出上限(100)。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdstring消息 ID(服务端生成的 messageId)
reactionIdstring见类型定义
options{pushConfig?:object}可选参数对象(可选)
返回

{messageId:string, reactionId:string, userId:string, reactionTime:uint64} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.addMessageReaction(IMPUpdateMessageReactionParam(conversationType: .privateChat, targetId: "user_001", messageId: "msg_001", reactionId: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func removeMessageReaction(_ param: IMPUpdateMessageReactionParam) async -> RcResult<IMPReactionRemoval>
自 1.1.0REST(HTTP)

移除自己对指定消息的回应;reactionId 须与添加时一致,未添加过时返回成功(removed=false)。 可能错误码:1001 参数错误、1004 用户不存在、1028 回应标识非法(1-16 字符)。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdstring消息 ID(服务端生成的 messageId)
reactionIdstring见类型定义
返回

{messageId:string, reactionId:string, removed:boolean} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.removeMessageReaction(IMPUpdateMessageReactionParam(conversationType: .privateChat, targetId: "user_001", messageId: "msg_001", reactionId: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func batchGetMessageReactionSummaries(_ param: IMPMessageReactionSummaryQuery) async -> RcResult<[String: [IMPMessageReactionSummary]]>
自 1.1.0REST(HTTP)

批量查询消息回应摘要(1-100 个 messageId)。返回按 messageId 分组:每个回应含总数、当前用户是否已回应、最近参与用户(最多 10 个);不存在回应的消息返回空数组。 可能错误码:1001 参数错误、1004 用户不存在。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdsstring[]消息 ID 列表
返回

Record<string, ReactionSummary[]>(ReactionSummary={reactionId:string,totalCount:uint32,hasCurrentUserReacted:boolean,reactionTime:uint64,users:{userId:string,reactionTime:uint64}[]}) 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.batchGetMessageReactionSummaries(IMPMessageReactionSummaryQuery(conversationType: .privateChat, targetId: "user_001", messageIds: ["user_001"]))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageReactions(_ param: IMPGetMessageReactionsParam) async -> RcResult<IMPMessageReactionPage>
自 1.1.0REST(HTTP)

分页查询指定消息的回应列表(count 1-50,默认 20;pageToken 不透明,空串表示第一页)。 可能错误码:1001 参数错误、1004 用户不存在。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdstring消息 ID(服务端生成的 messageId)
options{count?:uint32, pageToken?:string}可选参数对象(可选)
返回

{reactions:ReactionSummary[], pageToken?:string, totalCount:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageReactions(IMPGetMessageReactionsParam(conversationType: .privateChat, targetId: "user_001", messageId: "msg_001"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageReactionUsers(_ param: IMPGetMessageReactionUsersParam) async -> RcResult<IMPMessageReactionUserPage>
自 1.1.0REST(HTTP)

分页查询某个回应的参与用户(count 1-50,默认 20;pageToken 不透明)。 可能错误码:1001 参数错误、1004 用户不存在、1028 回应标识非法(1-16 字符)。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
messageIdstring消息 ID(服务端生成的 messageId)
reactionIdstring见类型定义
options{count?:uint32, pageToken?:string}可选参数对象(可选)
返回

{users:{userId:string,reactionTime:uint64}[], pageToken?:string, totalCount:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageReactionUsers(IMPGetMessageReactionUsersParam(conversationType: .privateChat, targetId: "user_001", messageId: "msg_001", reactionId: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func startStreamMessage(_ param: IMPStartStreamMessageParam) async -> RcResult<IMPStreamMessage>
自 1.2.0REST(HTTP)

开始一条流式消息(IDL rev17;客户端 REST `POST /api/apps/{appkey}/messages/stream/start`)。发送者取自用户 token;`content.text` 作为初始文本。返回 StreamMessage(streamId/messageId/status='streaming'/createdAt/text/segments),SDK 本地保留一个可增量渲染的流式占位消息。支持单聊(1)、群聊(2)、系统通知(4);聊天室(3)暂不支持(1001)。 可能错误码:1001 参数错误、1004 用户不存在、1005 群组不存在。

参数
参数类型说明
params{conversationType:ConversationType, targetId:string, content?:Content}见类型定义
返回

StreamMessage 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.startStreamMessage(IMPStartStreamMessageParam(conversationType: .privateChat, targetId: "user_001"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func appendStreamMessage(streamId: String, delta: String, seq: UInt32?) async -> RcResult<IMPStreamMessage>
自 1.2.0REST(HTTP)

追加一个流式增量(IDL rev17;客户端 REST `POST /api/apps/{appkey}/messages/stream/append`),返回累计文本/分段/状态的 StreamMessage;服务端同时向会话全部在线参与者广播 `stream_changed`(complete=false)。`seq` 重复时覆盖该段(乱序安全)。仅流发送者可调用(其他人 1003);流不存在 1001、已结束 1001。 可能错误码:1001 参数错误、1003 无权限。 可能触发事件:STREAM_MESSAGE_CHANGED。

参数
参数类型说明
streamIdstring见类型定义
deltastring见类型定义
options{seq?:uint32}可选参数对象(可选)
返回

StreamMessage 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.appendStreamMessage(streamId: "value", delta: "value", seq: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func completeStreamMessage(streamId: String) async -> RcResult<IMPStreamCompleteResult>
自 1.2.0REST(HTTP)

结束流式消息(IDL rev17;客户端 REST `POST /api/apps/{appkey}/messages/stream/end`):累计文本按 start 预分配的 messageId 落库为一条普通文本消息(恰一次),随后广播 `stream_changed`(complete=true)。返回 {streamId,messageId,text,status,complete,message?}。仅流发送者可调用(1003);空文本或已结束 1001。 可能错误码:1001 参数错误、1003 无权限。 可能触发事件:STREAM_MESSAGE_CHANGED、MESSAGES。

参数
参数类型说明
streamIdstring见类型定义
返回

{streamId:string, messageId:string, text:string, status:streaming|ended, complete:bool, message?:Message} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.completeStreamMessage(streamId: "value")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getStreamMessage(streamId: String) async -> RcResult<IMPStreamMessage>
自 1.2.0REST(HTTP)幂等

查询流式消息快照(IDL rev17;客户端 REST `GET /api/apps/{appkey}/messages/stream/{streamId}`),与 append 响应同形(StreamMessage)。仅会话参与者可见(单聊双方、群成员、聊天室在线成员;其他人 1003);未知流 1001。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
streamIdstring见类型定义
返回

StreamMessage 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getStreamMessage(streamId: "value")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getMessageExpansion(messageId: String) async -> RcResult<IMPMessageExpansion>
自 1.3.0REST(HTTP)幂等

读取已发送消息的扩展 KV(IDL rev19;客户端 REST `GET /api/apps/{appkey}/messages/{messageId}/expansion`),返回 `{messageId, expansion}`;无扩展/已全部删除时 expansion 为空 map。仅会话参与者可读(非参与者 1003);未知消息 1001;单聊对端用户不存在 1004、群不存在 1005、聊天室消息 1012。只读、幂等、不触发事件(写入仍由 updateMessageExpansion / removeMessageExpansion 完成)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在、1012 聊天室不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
messageIdstring消息 ID(服务端生成的 messageId)
返回

{messageId:string, expansion:Record<string,string>} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getMessageExpansion(messageId: "msg_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func combineMessages(_ messages: [IMPMessage], options: IMPCombineMessagesOptions?) -> RcResult<IMPCombineContent>
自 1.3.0本地(无 IO)幂等

本地构造合并转发内容(IDL rev19,transport=local,不做网络 IO):把 Message[] 转换为 `{type:'combine', title, items:[{senderId,senderName?,contentType,text?,timestamp?}]}`(`CombineContent`),随后直接 `sendMessage(conversationType, targetId, content)`。items 必须 1..=100(本地 1001);title <=64 字(缺省 ` 条聊天记录`);条目 text 按 textMaxChars(缺省 300)截断、全部条目合计 <=16KB;构造结果序列化后仍受 `limits.messageBytes`(5KB)约束,发送时超限为 1007。 可能错误码:1001 参数错误。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
messagesMessage[]见类型定义
options{title?:string, senderNames?:Record<string,string>, textMaxChars?:uint32}可选参数对象(可选)
返回

CombineContent 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = client.combineMessages([message], options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

会话(22)​

func getConversationList() async -> RcResult<[IMPConversation]>
自 1.0.0REST(HTTP)

会话列表:置顶优先、按 updatedAt 倒序;含未读/提及/草稿/免打扰。 可能错误码:无特定错误码(通用错误见 ErrorCode)。

返回

Conversation[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getConversationList()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getConversation(conversationType: IMPConversationType, targetId: String) async -> RcResult<IMPConversation>
自 1.0.0REST(HTTP)

单会话详情。 可能错误码:1001 参数错误。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

Conversation 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getConversation(conversationType: .privateChat, targetId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getHistoryMessages(conversationType: IMPConversationType, targetId: String, options: IMPHistoryOptions?) async -> RcResult<IMPHistoryPage>
自 1.0.0REST(HTTP)

历史消息分页(beforeSeq 向前翻页);limit 默认 20 上限 100。rev23:channelId 过滤超级群频道消息(仅返回该频道消息)。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
options{limit?:uint32, beforeSeq?:uint64, channelId?:string}可选参数对象(可选)
返回

{messages:Message[], hasMore:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getHistoryMessages(conversationType: .privateChat, targetId: "user_001", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func clearUnreadCount(conversationType: IMPConversationType, targetId: String) async -> RcResult<Void>
自 1.0.0长连接(WebSocket)幂等

清空会话未读(等价 read 帧 + 本地清零)。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 可能触发事件:CONVERSATION。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.clearUnreadCount(conversationType: .privateChat, targetId: "user_001")
func setConversationToTop(conversationType: IMPConversationType, targetId: String, isTop: Bool) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

会话置顶/取消。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
isTopbooltrue=置顶,false=取消置顶
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.setConversationToTop(conversationType: .privateChat, targetId: "user_001", isTop: true)
func saveTextMessageDraft(conversationType: IMPConversationType, targetId: String, draft: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

保存草稿(空串=清除)。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
draftstring草稿文本
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.saveTextMessageDraft(conversationType: .privateChat, targetId: "user_001", draft: "明天见")
func getTextMessageDraft(conversationType: IMPConversationType, targetId: String) async -> RcResult<String>
自 1.0.0REST(HTTP)

读取草稿;无草稿返回空串。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

string 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getTextMessageDraft(conversationType: .privateChat, targetId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func clearTextMessageDraft(conversationType: IMPConversationType, targetId: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

清除草稿。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.clearTextMessageDraft(conversationType: .privateChat, targetId: "user_001")
func setConversationNotificationLevel(conversationType: IMPConversationType, targetId: String, level: IMPNotificationLevel) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

会话提醒级别:0 全部 / 1 仅提及 / 2 免打扰。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
levelNotificationLevel提醒级别,取值见 NotificationLevel
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.setConversationNotificationLevel(conversationType: .privateChat, targetId: "user_001", level: IMPNotificationLevel.muted)
func createConversationTag(_ param: IMPCreateConversationTagParam) async -> RcResult<IMPConversationTag>
自 1.2.0REST(HTTP)

创建会话标签(tagName ≤16;单用户 ≤20 个,超出抛 1031)。 可能错误码:1001 参数错误、1031 单用户会话标签数超过上限(20)。

参数
参数类型说明
tagNamestring见类型定义
options{tagId?:string}可选参数对象(可选)
返回

ConversationTag 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.createConversationTag(IMPCreateConversationTagParam(tagName: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func updateConversationTag(_ param: IMPUpdateConversationTagParam) async -> RcResult<IMPConversationTag>
自 1.2.0REST(HTTP)幂等

重命名会话标签。 可能错误码:1001 参数错误、1032 标签不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
tagNamestring见类型定义
返回

ConversationTag 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.updateConversationTag(IMPUpdateConversationTagParam(tagId: "value", tagName: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func deleteConversationTag(tagId: String) async -> RcResult<Void>
自 1.2.0REST(HTTP)幂等

删除会话标签(同时清除标签内会话引用)。 可能错误码:1032 标签不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
返回

void 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
await client.deleteConversationTag(tagId: "value")
func getConversationTags() async -> RcResult<[IMPConversationTag]>
自 1.2.0REST(HTTP)幂等

获取全部会话标签(含会话数量)。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

返回

ConversationTag[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getConversationTags()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func addConversationsToTag(_ param: IMPTagConversationsParam) async -> RcResult<IMPConversationTagMembershipResult>
自 1.2.0REST(HTTP)幂等

把会话加入标签(≤100/次,幂等;≤1000/标签,超出抛 1033)。 可能错误码:1001 参数错误、1032 标签不存在、1033 标签内会话数超过上限(1000)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
conversationsConversationRef[]见类型定义
返回

{added:int, existing:int, conversationCount:int} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.addConversationsToTag(IMPTagConversationsParam(tagId: "value", conversations: [IMPConversationRef(conversationType: .privateChat, targetId: "user2")]))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func removeConversationsFromTag(_ param: IMPTagConversationsParam) async -> RcResult<IMPConversationTagMembershipResult>
自 1.2.0REST(HTTP)幂等

把会话移出标签(≤100/次,幂等)。 可能错误码:1001 参数错误、1032 标签不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
conversationsConversationRef[]见类型定义
返回

{removed:int, conversationCount:int} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.removeConversationsFromTag(IMPTagConversationsParam(tagId: "value", conversations: [IMPConversationRef(conversationType: .privateChat, targetId: "user2")]))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getConversationsFromTagByPage(_ param: IMPTagConversationsPageParam) async -> RcResult<IMPConversationTagPage>
自 1.2.0REST(HTTP)幂等

分页获取标签内会话(含置顶/未读数/最后消息时间)。 可能错误码:1032 标签不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
options{offset?:uint32, limit?:uint32}可选参数对象(可选)
返回

{total:int, items:ConversationTagConversation[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getConversationsFromTagByPage(IMPTagConversationsPageParam(tagId: "value"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getTagsFromConversation(conversationType: Int, targetId: String) async -> RcResult<[IMPConversationTag]>
自 1.2.0REST(HTTP)幂等

查询某个会话所属的标签列表。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

ConversationTag[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getTagsFromConversation(conversationType: 1, targetId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getUnreadCountByTag(tagId: String) async -> RcResult<IMPConversationTagUnread>
自 1.2.0REST(HTTP)幂等

标签内未读汇总(消息总数 + 有未读的会话数)。 可能错误码:1032 标签不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
返回

{unreadCount:int, unreadConversations:int, conversationCount:int} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getUnreadCountByTag(tagId: "value")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func setConversationToTopInTag(_ param: IMPTagTopParam) async -> RcResult<Void>
自 1.2.0REST(HTTP)幂等

标签内置顶/取消置顶会话(同步会话会话级置顶状态)。 可能错误码:1001 参数错误、1034 会话不存在(标签内置顶等操作要求会话已在标签内)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tagIdstring见类型定义
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
topbool见类型定义
返回

void 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
await client.setConversationToTopInTag(IMPTagTopParam(tagId: "value", conversationType: .privateChat, targetId: "user_001", top: true))
func deleteConversation(conversationType: Int, targetId: String) async -> RcResult<Bool>
自 1.2.0REST(HTTP)幂等

删除会话记录(列表项/未读/草稿/置顶),历史消息保留;同时从标签移除;幂等。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
targetIdstring目标 ID:单聊为对方 userId,群组为 groupId,聊天室为 chatroomId
返回

{removed:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.deleteConversation(conversationType: 1, targetId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getConversationTypeNotification(conversationType: Int) async -> RcResult<IMPConversationTypeNotification>
自 1.2.0REST(HTTP)幂等

查询按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)。 可能错误码:1001 参数错误。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
返回

{conversationType:int, level:int} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getConversationTypeNotification(conversationType: 1)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func setConversationTypeNotification(conversationType: Int, level: Int) async -> RcResult<IMPConversationTypeNotification>
自 1.2.0REST(HTTP)幂等

设置按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)。 可能错误码:1001 参数错误。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
conversationTypeConversationType会话类型,取值见 ConversationType
levelint提醒级别,取值见 NotificationLevel
返回

{conversationType:int, level:int} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.setConversationTypeNotification(conversationType: 1, level: 2)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

用户(10)​

func getUserProfile(userId: String) async -> RcResult<IMPUserProfile>
自 1.0.0REST(HTTP)

查询用户资料。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。

参数
参数类型说明
userIdstring用户 ID
返回

UserProfile 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getUserProfile(userId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func updateMyUserProfile(profile: IMPUserProfileUpdate) async -> RcResult<IMPUserProfile>
自 1.0.0REST(HTTP)

修改本人资料(name/avatarUrl)。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
profile{name?:string, avatarUrl?:string}待更新的资料字段(name / avatarUrl)
返回

UserProfile 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.updateMyUserProfile(profile: IMPUserProfileUpdate())
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getOnlineStatus(userId: String) async -> RcResult<IMPUserOnlineStatus>
自 1.0.0REST(HTTP)

查询单个用户在线状态。 可能错误码:1001 参数错误、1004 用户不存在。

参数
参数类型说明
userIdstring用户 ID
返回

{userId:string, online:bool, sessionCount:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getOnlineStatus(userId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getOnlineStatusBatch(userIds: [String]) async -> RcResult<IMPUserOnlineStatusBatch>
自 1.0.0REST(HTTP)

批量在线状态(<=100)。 可能错误码:1001 参数错误。

参数
参数类型说明
userIdsstring[]用户 ID 列表
返回

{items:[{userId:string,online:bool,sessionCount:uint32}]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getOnlineStatusBatch(userIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func subscribePresence(userIds: [String]) async -> RcResult<IMPPresenceSubscription>
自 1.4.0REST(HTTP)幂等

订阅用户在线状态(IDL rev20;客户端 REST `POST /api/apps/{appkey}/users/{userId}/presence/subscriptions`,userId 取自当前登录用户)。被订阅用户上线/离线/被踢/注销时通过长连接收到 `presence_changed`。订阅自己 1001;目标用户不存在/属于其它 app 1004;订阅总数上限 500(超限 1001);幂等(重复订阅不重复入列)。成功返回变更后的完整订阅列表 `{subscribed:[...]}`。好友关系本身已默认订阅对方在线状态,无需额外调用。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
userIdsstring[]用户 ID 列表
返回

{subscribed:string[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.subscribePresence(userIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func unsubscribePresence(userIds: [String]) async -> RcResult<IMPPresenceSubscription>
自 1.4.0REST(HTTP)幂等

取消订阅用户在线状态(IDL rev20;客户端 REST `POST .../presence/subscriptions` 的 `unsubscribe` 分支)。取消未订阅的用户幂等成功(不报错);订阅自己 1001;目标用户不存在 1004。成功返回变更后的完整订阅列表 `{subscribed:[...]}`。仅停止接收该用户的实时在线状态帧,好友关系不受影响。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
userIdsstring[]用户 ID 列表
返回

{subscribed:string[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.unsubscribePresence(userIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getPresenceSubscriptions() async -> RcResult<IMPPresenceSubscription>
自 1.4.0REST(HTTP)幂等

查询当前用户的在线状态订阅列表(IDL rev20;客户端 REST `GET /api/apps/{appkey}/users/{userId}/presence/subscriptions`)→ `{userId,subscribed:[...]}`。只读、幂等、不产生事件。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

返回

{userId:string, subscribed:string[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getPresenceSubscriptions()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func registerPushToken(options: IMPRegisterPushTokenOptions) async -> RcResult<IMPPushToken>
自 1.5.0REST(HTTP)幂等

注册设备推送 token(IDL rev21 C23 收口;客户端 REST `POST /api/apps/{appkey}/push/tokens`,服务端 rev20 已实现,本 op 补 SDK 语义面)→ PushToken。幂等键 `(userId, platform, token)`:重复注册返回既有 tokenId 并重新置 active=true;`token` 8..=512 字符、`platform` ∈ ios|android|web|huawei|xiaomi|oppo|vivo|fcm、未知平台/长度非法 1001、每用户 20 个活跃 token 上限(超限 1001)、注销/封禁用户 1016;同一 (platform, token) 被其它用户注册时旧记录置 active=false(设备换绑)。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1016 账号已被封禁。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
options{platform:string, token:string, deviceId?:string, appVersion?:string}可选参数对象
返回

PushToken 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.registerPushToken(options: IMPRegisterPushTokenOptions(platform: "value", token: "<user-token>"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func unregisterPushToken(tokenId: String) async -> RcResult<IMPUnregisterPushTokenResult>
自 1.5.0REST(HTTP)幂等

注销本人设备推送 token(IDL rev21 C23;客户端 REST `DELETE /api/apps/{appkey}/push/tokens/{tokenId}`):软删除 active=false 并保留历史供审计 → `{tokenId,userId,platform,deleted,active:false,alreadyInactive}`。非本人或不存在 1001(不泄露他人 token);重复注销幂等成功(alreadyInactive=true)。 可能错误码:1001 参数错误、1002 Token 无效或已过期。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
tokenIdstring见类型定义
返回

{tokenId:string, userId:string, platform:string, deleted:bool, active:bool, alreadyInactive:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.unregisterPushToken(tokenId: "value")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getPushTokens() async -> RcResult<IMPPushTokenListResult>
自 1.5.0REST(HTTP)幂等

查询本人设备推送 token(IDL rev21 C23;客户端 REST `GET /api/apps/{appkey}/push/tokens`)→ `{userId,tokens:[PushToken],total,activeTotal,platforms}`;含 active=false 历史,按 createdAt 倒序。只读、幂等、不产生事件。 可能错误码:1001 参数错误、1002 Token 无效或已过期。 该操作幂等:重复调用不会产生额外副作用。

返回

{userId:string, tokens:PushToken[], total:uint32, activeTotal:uint32, platforms:string[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getPushTokens()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

好友与黑名单(11)​

func searchUsers(keyword: String, options: IMPPageOptions?) async -> RcResult<IMPUserSearchResult>
自 1.0.0REST(HTTP)

搜索用户(userId/name,大小写不敏感,排除自己)。 可能错误码:1001 参数错误。

参数
参数类型说明
keywordstring搜索关键字
options{limit?:uint32}可选参数对象(可选)
返回

{users:[{userId:string,name:string,isFriend:bool,blacklisted:bool}], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.searchUsers(keyword: "ni", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func sendFriendRequest(toUserId: String, message: String?) async -> RcResult<IMPFriendRequest>
自 1.0.0REST(HTTP)

发起好友申请;已是好友/已有 pending → 1003;被拉黑 → 1011。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1011 已被对方拉黑或你已拉黑对方。 可能触发事件:FRIEND_EVENT。

参数
参数类型说明
toUserIdstring接收方 userId
messagestring附言 / 消息摘要(可选)
返回

FriendRequest 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.sendFriendRequest(toUserId: "user_002", message: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getFriendRequests(options: IMPFriendRequestQuery?) async -> RcResult<[IMPFriendRequest]>
自 1.0.0REST(HTTP)

好友申请列表(incoming/outgoing,pending/all)。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
options{type?:'incoming'|'outgoing', status?:'pending'|'all'}可选参数对象(可选)
返回

FriendRequest[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getFriendRequests(options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func acceptFriendRequest(requestId: String) async -> RcResult<IMPFriendRequest>
自 1.0.0REST(HTTP)

同意申请,双向建立好友关系。 可能错误码:1001 参数错误、1003 无权限。 可能触发事件:FRIEND_EVENT。

参数
参数类型说明
requestIdstring好友请求 ID(requestId)
返回

FriendRequest 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.acceptFriendRequest(requestId: "request_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func rejectFriendRequest(requestId: String) async -> RcResult<IMPFriendRequest>
自 1.0.0REST(HTTP)

拒绝申请。 可能错误码:1001 参数错误、1003 无权限。 可能触发事件:FRIEND_EVENT。

参数
参数类型说明
requestIdstring好友请求 ID(requestId)
返回

FriendRequest 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.rejectFriendRequest(requestId: "request_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getFriends() async -> RcResult<[IMPFriend]>
自 1.0.0REST(HTTP)

好友列表(含备注/在线/拉黑标记)。 可能错误码:无特定错误码(通用错误见 ErrorCode)。

返回

[{userId:string,name?:string,avatarUrl?:string,remark?:string,online?:bool,blacklisted?:bool}] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getFriends()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func deleteFriend(friendId: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

双向删除好友。 可能错误码:1001 参数错误、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
friendIdstring好友 userId
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.deleteFriend(friendId: "user_002")
func setFriendRemark(friendId: String, remark: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)

设置好友备注(<=64 字,空串清除)。 可能错误码:1001 参数错误、1003 无权限。

参数
参数类型说明
friendIdstring好友 userId
remarkstring好友备注名
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.setFriendRemark(friendId: "user_002", remark: "同事")
func getBlacklist() async -> RcResult<[IMPBlacklistEntry]>
自 1.0.0REST(HTTP)

黑名单列表。 可能错误码:无特定错误码(通用错误见 ErrorCode)。

返回

[{userId:string,name?:string}] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getBlacklist()
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func addToBlacklist(userId: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

加入黑名单(幂等;不能拉黑自己→1001)。 可能错误码:1001 参数错误、1004 用户不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
userIdstring用户 ID
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.addToBlacklist(userId: "user_001")
func removeFromBlacklist(userId: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)幂等

移出黑名单。 可能错误码:无特定错误码(通用错误见 ErrorCode)。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
userIdstring用户 ID
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.removeFromBlacklist(userId: "user_001")

群组(20)​

func createGroup(_ options: IMPCreateGroupOptions) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)

创建群(groupType 缺省 normal;joinPolicy 缺省 open;maxMembers 对 super 有效)。groupId 可由调用方指定(唯一)或服务端生成。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1015 成员数量超出上限、1021 服务未开通。

参数
参数类型说明
options{groupId?:string, name:string, owner?:string, members?:string[], groupType?:GroupType, joinPolicy?:JoinPolicy, maxMembers?:int}可选参数对象
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.createGroup(IMPCreateGroupOptions(name: "sample.png"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getGroupsInfo(groupIds: [String]) async -> RcResult<[IMPGroup]>
自 1.0.0REST(HTTP)

批量查询群信息(<=20)。 可能错误码:1001 参数错误。

参数
参数类型说明
groupIdsstring[]群组 ID 列表
返回

Group[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getGroupsInfo(groupIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getGroupMembers(groupId: String) async -> RcResult<[IMPGroupMember]>
自 1.0.0REST(HTTP)

群成员列表(含角色/禁言)。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在、1006 未加入群组。

参数
参数类型说明
groupIdstring群组 ID
返回

GroupMember[] 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getGroupMembers(groupId: "group_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func addGroupMembers(groupId: String, userIds: [String]) async -> RcResult<IMPAddGroupMembersResult>
自 1.0.0REST(HTTP)

拉人入群(群主/管理员;普通成员按配置)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在、1015 成员数量超出上限。

参数
参数类型说明
groupIdstring群组 ID
userIdsstring[]用户 ID 列表
返回

{added:string[], group:Group} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.addGroupMembers(groupId: "group_001", userIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func removeGroupMembers(groupId: String, userIds: [String]) async -> RcResult<IMPRemoveGroupMembersResult>
自 1.0.0REST(HTTP)

移除成员(群主/管理员;权限检查)。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在、1006 未加入群组。

参数
参数类型说明
groupIdstring群组 ID
userIdsstring[]用户 ID 列表
返回

{removed:string[]} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.removeGroupMembers(groupId: "group_001", userIds: ["user_001"])
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func quitGroup(groupId: String) async -> RcResult<Void>
自 1.0.0REST(HTTP)

退出群;群主需先转让。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在、1006 未加入群组。

参数
参数类型说明
groupIdstring群组 ID
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.quitGroup(groupId: "group_001")
func updateGroupName(groupId: String, name: String) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)

修改群名(群主/管理员)。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在。

参数
参数类型说明
groupIdstring群组 ID
namestring名称(群名称 / 文件名等)
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.updateGroupName(groupId: "group_001", name: "sample.png")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func updateGroupNotice(groupId: String, notice: String) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)

设置群公告(群主/管理员,<=500 字,空串清除)。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在。

参数
参数类型说明
groupIdstring群组 ID
noticestring群公告
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.updateGroupNotice(groupId: "group_001", notice: "欢迎加入群聊")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func transferGroupOwner(groupId: String, newOwner: String) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)

转让群主(新群主须为成员)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在。

参数
参数类型说明
groupIdstring群组 ID
newOwnerstring新群主 userId
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.transferGroupOwner(groupId: "group_001", newOwner: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func addGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)幂等

设置管理员(群主,幂等)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
groupIdstring群组 ID
userIdstring用户 ID
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.addGroupAdmin(groupId: "group_001", userId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func removeGroupAdmin(groupId: String, userId: String) async -> RcResult<IMPGroup>
自 1.0.0REST(HTTP)幂等

取消管理员(群主)。 可能错误码:1001 参数错误、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
groupIdstring群组 ID
userIdstring用户 ID
返回

Group 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.removeGroupAdmin(groupId: "group_001", userId: "user_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func muteGroupMember(groupId: String, userId: String, mutedUntil: UInt64) async -> RcResult<IMPMuteGroupMemberResult>
自 1.0.0REST(HTTP)

禁言/解禁(群主/管理员;不能禁言群主;管理员不能禁言管理员)。 可能错误码:1001 参数错误、1003 无权限、1004 用户不存在、1005 群组不存在、1006 未加入群组。

参数
参数类型说明
groupIdstring群组 ID
userIdstring用户 ID
mutedUntiluint64禁言截止时间(epoch ms)
返回

{groupId:string,userId:string,mutedUntil:uint64,group:Group} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.muteGroupMember(groupId: "group_001", userId: "user_001", mutedUntil: UInt64(Date().timeIntervalSince1970 * 1000) + 3_600_000)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func createSupergroupChannel(params: IMPCreateSupergroupChannelParams) async -> RcResult<IMPSupergroupChannel>
自 1.5.0REST(HTTP)

创建超级群频道(IDL rev21 C17;客户端 REST `POST /api/apps/{appkey}/supergroup/channels`)→ SupergroupChannel。channelId 服务端生成(`ch_`,应用内唯一);joinPolicy 由 type 推导(public→open、private→invite),与之矛盾的显式取值 1001;仅群主/管理员可调用(否则 1003),群不存在 1005,单群 100 频道上限(超限 1015)。与 Open API `supergroup.channel.create` 共享状态。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在、1015 成员数量超出上限。

参数
参数类型说明
params{groupId:string, name:string, type:ChannelType, joinPolicy?:JoinPolicy}见类型定义
返回

SupergroupChannel 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.createSupergroupChannel(params: IMPCreateSupergroupChannelParams(groupId: "group_001", name: "sample.png", type: .public))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func listSupergroupChannels(groupId: String) async -> RcResult<IMPSupergroupChannelListResult>
自 1.5.0REST(HTTP)幂等

超级群频道列表(IDL rev21 C17;客户端 REST `GET /api/apps/{appkey}/supergroup/channels?groupId=`)→ `{groupId,channels:[SupergroupChannel],total}`。仅群成员可读(否则 1003),群不存在 1005,缺 groupId 1001。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
groupIdstring群组 ID
返回

{groupId:string, channels:SupergroupChannel[], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.listSupergroupChannels(groupId: "group_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func joinSupergroupChannel(channelId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPJoinSupergroupChannelResult>
自 1.5.0REST(HTTP)幂等

加入超级群频道(IDL rev21 C17;客户端 REST `POST .../supergroup/channels/{channelId}/join`,幂等)→ `{groupId,channelId,userId,joined:true,alreadyJoined}`。public 频道群成员可直接加入;private 频道需已受邀或为群主/管理员(否则 1003)。频道不存在 1005;channelId 跨群同名时可通过第二参数 `{groupId}` 消歧(未消歧 1001);非群成员 1003。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
channelIdstring见类型定义
options{groupId?:string}可选参数对象(可选)
返回

{groupId:string, channelId:string, userId:string, joined:bool, alreadyJoined:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.joinSupergroupChannel(channelId: "value", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func leaveSupergroupChannel(channelId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPLeaveSupergroupChannelResult>
自 1.5.0REST(HTTP)幂等

离开超级群频道(IDL rev21 C17;客户端 REST `POST .../supergroup/channels/{channelId}/leave`,幂等)→ `{groupId,channelId,userId,left:true,wasMember}`;不在频道内也返回成功(wasMember=false)。频道不存在 1005、非群成员 1003。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
channelIdstring见类型定义
options{groupId?:string}可选参数对象(可选)
返回

{groupId:string, channelId:string, userId:string, left:bool, wasMember:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.leaveSupergroupChannel(channelId: "value", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func bindUserGroupToChannel(channelId: String, userGroupId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPBindUserGroupToChannelResult>
自 1.5.0REST(HTTP)幂等

把用户组绑定到频道(IDL rev21 C17;客户端 REST `POST .../supergroup/channels/{channelId}/usergroups`,幂等)→ `{groupId,channelId,userGroupId,bound:true,reverseIndexed}`。**双向维护** SupergroupChannel.userGroupIds 与 UserGroup.channelIds(rev21 修复 rev7 仅写频道侧导致的反向索引缺失),因此 `listUserGroups`/`getUserGroupsByUser` 的 channelIds 反查可用。仅群主/管理员(否则 1003);频道/用户组不存在 1005。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
channelIdstring见类型定义
userGroupIdstring见类型定义
options{groupId?:string}可选参数对象(可选)
返回

{groupId:string, channelId:string, userGroupId:string, bound:bool, reverseIndexed:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.bindUserGroupToChannel(channelId: "value", userGroupId: "value", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func createUserGroup(params: IMPCreateUserGroupParams) async -> RcResult<IMPUserGroup>
自 1.5.0REST(HTTP)

创建超级群用户组(IDL rev21 C17;客户端 REST `POST /api/apps/{appkey}/supergroup/usergroups`)→ UserGroup。userGroupId 服务端生成(`ug_`);members 去空/去重/保序,每项必须是本群成员(否则 1003)、用户不存在 1004;仅群主/管理员(否则 1003);参数非法 1001、单群 100 用户组上限(超限 1015)。与 Open API `supergroup.usergroup.*` 共享状态。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1004 用户不存在、1015 成员数量超出上限。

参数
参数类型说明
params{groupId:string, name:string, members?:string[]}见类型定义
返回

UserGroup 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.createUserGroup(params: IMPCreateUserGroupParams(groupId: "group_001", name: "sample.png"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func listUserGroups(groupId: String) async -> RcResult<IMPUserGroupListResult>
自 1.5.0REST(HTTP)幂等

超级群用户组列表(IDL rev21 C17;客户端 REST `GET /api/apps/{appkey}/supergroup/usergroups?groupId=`)→ `{groupId,userGroups:[UserGroup],total}`;UserGroup.channelIds 为频道反向索引(rev21 修复后可用)。仅群成员可读(否则 1003),群不存在 1005,缺 groupId 1001。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限、1005 群组不存在。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
groupIdstring群组 ID
返回

{groupId:string, userGroups:UserGroup[], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.listUserGroups(groupId: "group_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getUserGroupsByUser(userId: String, options: IMPSupergroupChannelOptions?) async -> RcResult<IMPUserGroupListResult>
自 1.5.0REST(HTTP)幂等

查询某用户所在的所有用户组(IDL rev21 C17;客户端 REST `GET .../supergroup/usergroups/by-user/{userId}`)→ `{userId,userGroups:[UserGroup],total}`。仅本人可查(userId ≠ 当前登录用户 1003);`options.groupId` 可限定单个群;只返回「本人确实在该群」的用户组(群已删除的不返回,不虚构)。 可能错误码:1001 参数错误、1002 Token 无效或已过期、1003 无权限。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
userIdstring用户 ID
options{groupId?:string}可选参数对象(可选)
返回

{userId:string, userGroups:UserGroup[], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getUserGroupsByUser(userId: "user_001", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

聊天室(5)​

func createChatroom(options: IMPCreateChatroomOptions) async -> RcResult<IMPChatroom>
自 1.0.0REST(HTTP)

创建聊天室(客户端能力;服务端 Open API 亦可创建)。chatroomId 可指定或服务端生成。 可能错误码:1001 参数错误、1003 无权限、1015 成员数量超出上限、1021 服务未开通。

参数
参数类型说明
options{chatroomId?:string, name:string, owner?:string}可选参数对象
返回

Chatroom 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.createChatroom(options: IMPCreateChatroomOptions(name: "sample.png"))
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func joinChatroom(chatroomId: String) async -> RcResult<IMPChatroom>
自 1.0.0长连接(WebSocket)幂等

加入聊天室:发送 chatroom_join,收到 chatroom_joined;房内广播 member_changed。 可能错误码:1001 参数错误、1012 聊天室不存在、1013 聊天室已销毁、3001 长连接未就绪。 可能触发事件:CHATROOM_EVENT。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
chatroomIdstring聊天室 ID
返回

Chatroom 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.joinChatroom(chatroomId: "chatroom_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func leaveChatroom(chatroomId: String) async -> RcResult<Void>
自 1.0.0长连接(WebSocket)幂等

离开聊天室。 可能错误码:1001 参数错误、1012 聊天室不存在、3001 长连接未就绪。 可能触发事件:CHATROOM_EVENT。 该操作幂等:重复调用不会产生额外副作用。

参数
参数类型说明
chatroomIdstring聊天室 ID
返回

void / null 无业务返回值;失败时通过返回信封 code 或回调错误对象表达。

示例
Swift
await client.leaveChatroom(chatroomId: "chatroom_001")
func getChatroomInfo(chatroomId: String) async -> RcResult<IMPChatroom>
自 1.0.0REST(HTTP)

聊天室信息(含在线数)。 可能错误码:1001 参数错误、1012 聊天室不存在。

参数
参数类型说明
chatroomIdstring聊天室 ID
返回

Chatroom 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getChatroomInfo(chatroomId: "chatroom_001")
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}
func getChatroomMembers(chatroomId: String, options: IMPPageOptions?) async -> RcResult<IMPChatroomMembersPage>
自 1.0.0REST(HTTP)

聊天室在线成员列表。 可能错误码:1001 参数错误、1012 聊天室不存在。

参数
参数类型说明
chatroomIdstring聊天室 ID
options{offset?:uint32,limit?:uint32}可选参数对象(可选)
返回

{members:ChatroomMember[], total:uint32} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getChatroomMembers(chatroomId: "chatroom_001", options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

系统通知(1)​

func getSystemMessages(options: IMPHistoryOptions?) async -> RcResult<IMPHistoryPage>
自 1.0.0REST(HTTP)

系统通知历史(会话 conversationType=SYSTEM,targetId='system')。 可能错误码:1001 参数错误。

参数
参数类型说明
options{limit?:uint32,beforeSeq?:uint64}可选参数对象(可选)
返回

{messages:Message[], hasMore:bool} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.getSystemMessages(options: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

文件上传(1)​

func uploadFile(data: Data, name: String, mime: String?) async -> RcResult<IMPUploadResult>
自 1.0.0REST(HTTP)

上传文件(<=20MB),返回可用于图片/文件/语音消息的 url。 可能错误码:1001 参数错误、1003 无权限、1007 消息体过大(上限 5KB)。

参数
参数类型说明
databytes|blob文件二进制内容
namestring名称(群名称 / 文件名等)
mimestring文件 MIME 类型(可选)
返回

{url:string,name:string,size:uint64,mime:string,fullUrl?:string} 成功时返回上述类型;失败时返回信封 code(RcResult 泛型信封)或回调错误对象。

示例
Swift
let result = await client.uploadFile(data: Data(), name: "sample.png", mime: nil)
if result.code != 0 {
    print(result.code)
    print(result.msg ?? "")
}

相关链接​