按会话类型设置免打扰
会话类型默认级别用于“所有群都静音”“所有聊天室都静音”这类批量偏好;单会话设置仍可覆盖它。
getConversationTypeNotification
查询按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)。
| 项 | 值 |
|---|---|
| Swift | func getConversationTypeNotification(conversationType: Int) async -> RcResult<IMPConversationTypeNotification> |
| Objective-C | - (void)getConversationTypeNotificationWithConversationType:(NSInteger)conversationType completion:(void (^)(IMPOSResult *result))completion |
| 传输 | REST(HTTP) |
| 幂等 | 是 |
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
conversationType | ConversationType | 是 | 会话类型枚举(ConversationType) |
返回
{conversationType:int, level:int}:成功返回的数据;失败时按错误码处理
示例(Swift / Objective-C)
let res = await client.getConversationTypeNotification(conversationType: 1)
if res.code != 0 { print(res.msg ?? "") }[client getConversationTypeNotificationWithConversationType:1 /* 单聊 */ completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];错误码
| 错误码 | 名称 | 分类 | HTTP | 可重试 | 说明 |
|---|---|---|---|---|---|
1001 | INVALID_PARAMETER | 客户端 / 参数 / 权限 | 400 | 否 | 参数错误 |
setConversationTypeNotification
设置按会话类型默认免打扰级别(0 全部 / 1 仅 @ / 2 免打扰)。
| 项 | 值 |
|---|---|
| Swift | func setConversationTypeNotification(conversationType: Int, level: Int) async -> RcResult<IMPConversationTypeNotification> |
| Objective-C | - (void)setConversationTypeNotificationWithConversationType:(NSInteger)conversationType level:(NSInteger)level completion:(void (^)(IMPOSResult *result))completion |
| 传输 | REST(HTTP) |
| 幂等 | 是 |
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
conversationType | ConversationType | 是 | 会话类型枚举(ConversationType) |
level | int | 是 | 字段含义见类型定义 |
返回
{conversationType:int, level:int}:成功返回的数据;失败时按错误码处理
示例(Swift / Objective-C)
let setRes = await client.setConversationTypeNotification(conversationType: 1, level: 2)
if setRes.code != 0 { print(setRes.msg ?? "") }[client setConversationTypeNotificationWithConversationType:1 /* 单聊 */ level:2 /* 免打扰 */ completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];错误码
| 错误码 | 名称 | 分类 | HTTP | 可重试 | 说明 |
|---|---|---|---|---|---|
1001 | INVALID_PARAMETER | 客户端 / 参数 / 权限 | 400 | 否 | 参数错误 |
使用示例
let groupRes = await client.setConversationTypeNotification(conversationType: 2, level: 1)
if groupRes.code != 0 { print(groupRes.msg ?? "") }[client setConversationTypeNotificationWithConversationType:2 /* 群聊 */
level:1
completion:^(IMPOSResult *result) {
if (result.code != 0) { NSLog(@"set failed: %@", result.msg); }
}];
[client getConversationTypeNotificationWithConversationType:2 /* 群聊 */
completion:^(IMPOSResult *result) {
NSLog(@"group default level = %@", result.data);
}];优先级示例
| 类型默认 | 单会话设置 | 实际行为 |
|---|---|---|
| 2(免打扰) | 未设置 | 所有该类型会话免打扰 |
| 2(免打扰) | 0(全部提醒) | 该会话正常提醒(单会话覆盖类型) |
| 0(全部提醒) | 1(仅 @) | 该会话仅 @ 提醒 |
| 2(免打扰) | 1(仅 @) | 该会话仅 @ 提醒 |