全局免打扰

全局免打扰:免打扰按全局(夜间时段)与会话/会话类型两级控制;全局免打扰在客户端本地判断是否提醒。

适用场景​

  • 夜间 22:00–08:00 不弹通知
  • 单个群/会话静音但仍计入未读
  • 多端同步免打扰状态

前置条件​

  • 已连接并拿到会话/用户配置
  • 宿主负责系统通知权限与展示
  • 免打扰状态需要持久化到本地

融云行为(对照)​

融云文档中「全局免打扰」提供完整的页面/流程说明(原文见 ios-imlib/notification/do-not-disturb);其能力通常由 IMLib + 服务端或其他产品组件共同实现。

我们的实现与替代​

当前以 IMLib 已有能力组合实现。 会话/类型级用 setConversationNotificationLevel / setConversationTypeNotification;全局免打扰时段(5 个接口)未覆盖,客户端用本地计时 + UNUserNotificationCenter 降级。

差异与排期​

  • 当前 IMLib 契约未提供该主题的直接 op:该主题属于服务端/宿主页面能力,SDK 不提供同名接口。
  • 本站不提供占位/伪造接口;页面只描述可验证的替代路径与需要宿主补齐的部分。
  • 如业务强依赖该能力,建议在服务端/宿主侧实现,并在「功能列表」页登记差异。

迁移建议​

  1. 先按现有 IMLib 能力把核心链路(连接/消息/会话)跑通。
  2. 把该主题拆为「服务端接口 + 客户端展示」两部分,分别排期。
  3. 实现后补充本页的 API、示例与验收用例,并更新功能列表。
不伪造已实现

本页是能力边界说明,不代表 SDK 已提供同名接口;接口面以 API 参考与冻结契约为准。

能力与 API​

以下操作来自冻结的 sdk-imlib.json;签名与参数逐字取自 sdk-bindings.json → bindings.ios.imlib.methodMap。

操作Swift 签名返回参数
getConversationTypeNotificationfunc getConversationTypeNotification(conversationType: Int) async -> RcResult<IMPConversationTypeNotification>{conversationType:int, level:int}conversationType:ConversationType
setConversationTypeNotificationfunc setConversationTypeNotification(conversationType: Int, level: Int) async -> RcResult<IMPConversationTypeNotification>{conversationType:int, level:int}conversationType:ConversationType, level:int
setConversationNotificationLevelfunc setConversationNotificationLevel(conversationType: IMPConversationType, targetId: String, level: IMPNotificationLevel) async -> RcResult<Void>nullconversationType:ConversationType, targetId:string, level:NotificationLevel

完整字段与错误码见 API 参考;示例可直接复制到 Swift/Objective-C 工程。

Swift / Objective-C 示例​

let res = await client.getConversationTypeNotification(conversationType: 1)
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client getConversationTypeNotificationWithConversationType:1 /* 单聊 */ completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
let res = await client.setConversationTypeNotification(conversationType: 1, level: 2)
if res.code != 0 { print("IM 调用失败:\(res.msg ?? "")") }
[client setConversationTypeNotificationWithConversationType:1 /* 单聊 */ level:2 /* 免打扰 */ completion:^(IMPOSResult *result) {
    if (result.code != 0) { NSLog(@"IM 调用失败:%ld %@", (long)result.code, result.msg); }
}];
错误处理

IMLib 不 throw:检查 res.code。常见:1002 Token 无效、1001 参数错误、3001 未连接(可重试)、3002 超时。完整码表见 状态码。

与融云对应页 / 差异​

项内容
融云页面ios-imlib/notification/do-not-disturb(全局免打扰)
融云接口状态能力缺失(写边界页)
我方对应getConversationTypeNotification、setConversationTypeNotification、setConversationNotificationLevel(本项目可用 op,非融云同名接口)
差异说明全局免打扰时段:setNotificationQuietHoursLevel、setNotificationQuietHoursWithSetting、getNotificationQuietHoursLevel、getNotificationQuietHoursSetting、removeNotificationQuietHours
能力缺口(如实标注)

融云该页描述的能力未完全在 IMLib 102 op / 16 事件中覆盖:全局免打扰时段:setNotificationQuietHoursLevel、setNotificationQuietHoursWithSetting、getNotificationQuietHoursLevel、getNotificationQuietHoursSetting、removeNotificationQuietHours。本页上方列出的 op 为本项目可用能力(替代/部分覆盖),不是融云同名接口。

相关错误码​

错误码名称含义处理
1001INVALID_PARAMETER参数错误修正参数/权限后重试
1002INVALID_TOKENToken 无效或已过期修正参数/权限后重试
1007MESSAGE_TOO_LARGE消息体过大(上限 5KB)修正参数/权限后重试
1009GROUP_MUTED你已被禁言修正参数/权限后重试
1010SENSITIVE_WORD内容包含敏感词修正参数/权限后重试
3001SDK_NOT_CONNECTED长连接未就绪可重试(退避)
3002SDK_TIMEOUT请求超时可重试(退避)
3003SDK_NETWORK_ERROR网络错误可重试(退避)

排查建议​

  • 先确认 client.getConnectionStatus() 为 connected,再调用业务 op。
  • 按错误码区分:1001/1007 修正参数;1002/1003 重新登录;3001/3002 退避重试。
  • 本地数据异常时先查看本地库路径与迁移日志,再清缓存复现。

相关页面​