圈组系统通知(已废弃)

更新时间: 2023/07/21 06:54:54

本文已不再维护,请前往圈组系统通知相关查看更新的文档。

圈组系统通知概览

系统通知可分为内置系统通知和自定义系统通知。

系统通知类型 说明 离线系统通知限制
内置系统通知 圈组内置的系统通知, 类型包括“邀请服务器成员”、“踢除服务器成员”、“修改频道信息” 等 服务器成员管理事件的系统通知支持存离线,每月至多存 1,000 条离线通知。其他内置系统通知不存离线
自定义系统通知 开发者自定义系统通知。 SDK 不解析自定义系统通知,仅负责传递 每月 1,000 条离线通知

内置系统通知分类

圈组内置系统通知,可进一步分为服务器成员管理事件的系统通知服务器其他相关事件的系统通知频道事件系统通知频道分组事件系统通知身份组成员管理事件的系统通知身份组权限事件系统通知。除了服务器成员管理事件的系统通知,其余类型都通过参与者与观察者机制控制接收人及其接收条件。

每个类型的具体触发条件和接收条件,请参考服务端的圈组系统通知

技术原理

圈组中的系统通知是由云信服务器下发给用户的通知类消息,用于包括创建 Server、创建 Channel、申请加入 Server 等事件的通知。

SDK 通过 NIMQChatSystemNotification 来定义圈组的系统通知。

NIMQChatSystemNotification 的参数如下:

返回值类型 参数 说明
unsinged long long serverId 通知所属的圈组服务器的 ID
unsinged long long channelId 通知所属的频道的 ID
NSArray<NSString*> toAccids 通知接收者账号列表
NSString fromAccount 通知发送者的 accid
NIMQChatSystemNotificationToType toType 通知发送对象类型。主要分为服务器,服务器成员,频道,频道成员
NSInteger fromClientType 通知发送者的客户端类型
NSString fromDeviceId 发送方设备 ID
NSString fromNick 发送方昵称
NSTimeInterval time 消息发送时间
NSTimeInterval updateTime 通知更新时间
NIMQChatSystemNotificationType type 通知类型,具体系统通知类型的接收条件等信息,可参考服务器的 QChatSystemMsgType
NSString messageClientId 客户端生成的消息 ID,会用于去重
unsigned long long messageServerID 服务器生成的通知 ID,全局唯一
NSString body 通知内容
NIMQChatSystemNotificationAttachment attach 通知附件
NSString ext 扩展字段,推荐使用 JSON 格式
NSInteger status 状态,可以自定义。默认为 0,大于 10,000 为用户自定义的状态,具体可查看NIMQChatSystemNotificationStatus
NSString pushPayload 第三方自定义的推送属性,限制使用 JSON 格式
NSString pushContent 自定义推送文案
NIMQChatSystemNotificationSetting setting 自定义系统通知设置,如是否需要计入推送未读,是否需要带推送前缀等
NSString env 环境变量,用于指向不同的抄送,第三方回调等配置
NSString callbackExt 获取第三方回调回来的自定义扩展字段

实现方法

发送自定义系统通知

SDK 提供发送自定义系统通知的能力。

SDK 通过圈组消息 NIMQChatMessageManager 中的 sendSystemNotification 发送自定义系统通知。

  • 接口原型
objc/**
 * 发送自定义系统通知
 *
 * @param param 传入参数
 * @param completion 结果回调
 */
- (void)sendSystemNotification:(NIMQChatSendSystemNotificationParam *)param
                    completion:(nullable NIMQChatSendSystemNotificationHandler)completion;

其中 NIMQChatSendSystemNotificationParam 是发送自定义系统通知入参。

  • 示例代码
objcid<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager];
NIMQChatSendSystemNotificationParam *param = [[NIMQChatSendSystemNotificationParam alloc] initWithServerId:123456 channelId:121212];
param.body = @"系统通知内容";
[qchatMessageManager sendSystemNotification:param
                completion:^(NSError *__nullable error, NIMQChatSendSystemNotificationResult *__nullable result) {
    // your code
}];

重发自定义系统通知

SDK 支持重发自定义系统通知,重发已经发送成功的自定义系统通知。通知接收方不会再次收到系统通知。

SDK 通过圈组消息 NIMQChatMessageManager 中的 resendSystemNotification 重新发送自定义系统通知。

  • 接口原型
objc/**
 * 重发自定义系统通知
 *
 * @param param 传入参数
 * @param completion 结果回调
 */
- (void)resendSystemNotification:(NIMQChatResendSystemNotificationParam *)param
                    completion:(nullable NIMQChatSendSystemNotificationHandler)completion;

其中 NIMQChatResendSystemNotificationParam 是重发自定义系统通知入参。

  • 示例代码
objcid<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager];
NIMQChatResendSystemNotificationParam *param = [[NIMQChatResendSystemNotificationParam alloc] init];
param.systemNotification = systemNotification;
[qchatMessageManager resendSystemNotification:param
                  completion:^(NSError *__nullable error, NIMQChatSendSystemNotificationResult *__nullable result) {
    // your code
}];

圈组系统通知接收事件回调

SDK 通过圈组消息管理器回调 NIMQChatMessageManagerDelegate 中的 onRecvSystemNotification 回调系统通知接收事件。

  • 接口原型
objc/**
 * 圈组系统通知接收事件回调
 *
 * @param result 结果详情
 */
- (void)onRecvSystemNotification:(NIMQChatReceiveSystemNotificationResult *)result;

其中NIMQChatReceiveSystemNotificationResult 是圈组系统通知接收事件的回调类型。

  • 示例代码
objc// 添加监听
- (void)addListener {
    [[[NIMSDK sharedSDK] qchatMessageManager] addDelegate:self];
}

// 移除监听
- (void)removeListener {
    [[[NIMSDK sharedSDK] qchatMessageManager] removeDelegate:self];
}

// 回调方法
- (void)qchatKickedOut:(NIMLoginKickoutResult *)result {
    // your code
}

更新系统通知

对于已发送的系统通知,可以修改系统通知中部分信息。

SDK 通过圈组消息 NIMQChatMessageManager 中的 updateSystemNotification 更新系统通知。

  • 接口原型
objc/**
 * 更新系统通知(可以更新状态、也可以更新内容)
 */
- (void)updateSystemNotification:(NIMQChatUpdateSystemNotificationParam *)param
             completion:(nullable NIMQChatUpdateSystemNotificationHandler)completion;

其中 NIMQChatUpdateSystemNotificationParam 是更新系统通知入参。

  • 示例代码
objcid<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager];
NIMQChatUpdateSystemNotificationParam *param = [[NIMQChatUpdateSystemNotificationParam alloc] init];
param.msgServerId = systemNotification.messageServerID;
param.notificationType = NIMQChatSystemNotificationTypeCustom;
param.status = 10000;

//更新设置
NIMQChatUpdateParam *universalUpdateInfo = [NIMQChatUpdateParam new];
universalUpdateInfo.postscript = @"更新系统通知";
universalUpdateInfo.pushContent = @"更新了系统通知";
universalUpdateInfo.env = @"***";
universalUpdateInfo.routeEnable = YES;

param.updateParam = universalUpdateInfo;

[qchatMessageManager updateSystemNotification:param
                  completion:^(NSError *__nullable error, NIMQChatUpdateSystemNotificationResult *__nullable result) {
    // your code
}];

圈组系统通知更新事件回调

SDK 通过圈组消息管理器回调 NIMQChatMessageManagerDelegate 中的 onSystemNotificationUpdate 回调系统通知更新事件。

  • 接口原型
objc/**
 * 圈组系统通知更新事件回调
 *
 * @param result 结果详情
 */
- (void)onSystemNotificationUpdate:(NIMQChatSystemNotificationUpdateResult *)result;

其中NIMQChatSystemNotificationUpdateResult 是圈组系统通知更新同步事件回调参数类型。

  • 示例代码
objc// 添加监听
- (void)addListener {
    [[[NIMSDK sharedSDK] qchatMessageManager] addDelegate:self];
}

// 移除监听
- (void)removeListener {
    [[[NIMSDK sharedSDK] qchatMessageManager] removeDelegate:self];
}

// 回调方法
- (void)qchatKickedOut:(NIMLoginKickoutResult *)result {
    // your code
}

标记系统通知已读

可以对系统通知标记已读。标记已读后的系统通知将从服务端删除,后续不会在其他端接收到了。

SDK 通过圈组消息 NIMQChatMessageManager 中的 markSystemNotificationsRead 标记系统通知已读。

  • 接口原型
objc/**
 * 标记系统通知已读
 *
 * @param param 传入参数
 * @param completion 结果回调
 */
- (void)markSystemNotificationsRead:(NIMQChatMarkSystemNotificationsReadParam *)param
                         completion:(nullable NIMQChatHandler)completion;

其中 NIMQChatMarkSystemNotificationsReadParam 是标记系统通知已读的入参。

  • 示例代码
objcid<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager];
NIMQChatMarkSystemNotificationsReadParam *param = [[NIMQChatMarkSystemNotificationsReadParam alloc] init];
NIMQChatMarkSystemNotificationsReadItem *item = [[NIMQChatMarkSystemNotificationsReadItem alloc] init];
item.messageServerId = 10101010;
item.type = NIMQChatSystemNotificationTypeCustom;
param.items = @[item];
[qchatMessageManager markSystemNotificationsRead:param
                     completion:^(NSError *__nullable error) {
    // your code
}];
此文档是否对你有帮助?
有帮助
去反馈
  • 圈组系统通知概览
  • 内置系统通知分类
  • 技术原理
  • 实现方法
  • 发送自定义系统通知
  • 重发自定义系统通知
  • 圈组系统通知接收事件回调
  • 更新系统通知
  • 圈组系统通知更新事件回调
  • 标记系统通知已读