圈组系统通知更新
更新时间: 2023/09/13 17:02:36
NIM SDK 支持更新已发送的圈组系统通知。
功能介绍
用户可通过 NIMQChatMessageManager
中的 updateSystemNotification:completion:
方法更新圈组系统通知的部分信息,如系统通知中的内容、自定义扩展字段等。
支持更新的圈组系统通知类型如下表所示:
系统通知分类 | NIMQChatSystemNotificationType 的枚举值 | 相关限制 | |
---|---|---|---|
内置系统通知 | 邀请服务器成员 | NIMQChatSystemNotificationTypeServerMemberInvite |
默认自动存离线。这四种通知每月总共至多存 1000 条离线,超限后将无法更新通知的信息 |
拒绝邀请 | NIMQChatSystemNotificationTypeServerMemberInviteReject |
||
申请加入服务器 | NIMQChatSystemNotificationTypeServerMemberApply |
||
拒绝申请 | NIMQChatSystemNotificationTypeServerMemberApplyReject |
||
自定义系统通知 | NIMQChatSystemNotificationTypeCustom |
只有存离线的自定义系统通知才能更新。每月至多存 1000 条离线,超限后将无法更新通知的信息 |
- 只有指明通知接收者的自定义系统通知才能设置存离线,即圈组系统通知对象的
toAccids
不为空。 - 其他内置系统通知,不支持更新。具体的内置系统通知类型,请参见内置系统通知类型。
实现方法
本文以服务器所有者(即创建者)和服务器成员的交互为例,介绍服务器成员更新圈组自定义系统通知和内置系统通知的实现流程。
前提条件
如果用户所在服务器的成员人数超过 2000 人阈值,该用户还需先订阅相应的服务器或频道,才能收到对应服务器或频道的系统通知。如未超过该阈值,则无需订阅。订阅相关说明,请参见圈组订阅机制。
实现流程
以下只对部分重要步骤进行说明:
-
服务器成员在登录圈组前,注册
onRecvSystemNotification:
和onSystemNotificationUpdate:
分别监听圈组系统通知接收和圈组系统通知更新状态。示例代码:
监听圈组系统通知接收// 添加监听 - (void)addListener { [[[NIMSDK sharedSDK] qchatMessageManager] addDelegate:self]; } // 移除监听 - (void)removeListener { [[[NIMSDK sharedSDK] qchatMessageManager] removeDelegate:self]; } // 回调方法 - (void)qchatKickedOut:(NIMLoginKickoutResult *)result { // your code }
圈组系统通知更新状态// 添加监听 - (void)addListener { [[[NIMSDK sharedSDK] qchatMessageManager] addDelegate:self]; } // 移除监听 - (void)removeListener { [[[NIMSDK sharedSDK] qchatMessageManager] removeDelegate:self]; } // 回调方法 - (void)qchatKickedOut:(NIMLoginKickoutResult *)result { // your code }
-
服务器所有者通过调用
sendSystemNotification:
发送圈组自定义系统通知。发送的圈组自定义系统通知需要存离线,并指明通知对象,即圈组系统通知的NIMQChatSystemNotificationSetting.persistEnable
为 true 且toAccids
不为空。若需要在发送自定义系统通知前提前构造一个系统通知对象,您可以通过
toQChatSystemNotification
构造圈组自定义系统通知。示例代码:
id<NIMQChatMessageManager> qchatMessageManager = [[NIMSDK sharedSDK] qchatMessageManager]; NIMQChatSendSystemNotificationParam *param = [[NIMQChatSendSystemNotificationParam alloc] initWithServerId:123456 channelId:121212]; param.body = @"系统通知内容"; NIMQChatSystemNotificationSetting *setting = [[NIMQChatSystemNotificationSetting alloc] init]; setting.persistEnable = YES; param.setting = setting; param.toAccids = @[@(accid), @(accid), @(accid)]; [qchatMessageManager sendSystemNotification:param completion:^(NSError *__nullable error, NIMQChatSendSystemNotificationResult *__nullable result) { // your code }];
-
服务器成员收到来自服务器所有者的系统通知。
-
服务器成员调用
updateSystemNotification:
更新圈组系统通知。其中
NIMQChatUpdateMessageParam
是更新圈组系统通知的入参。示例代码:
id<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 }];
-
服务器成员收到更新后的圈组系统通知。