获取未读消息数
IMLib SDK 支持您获取超级群下的未读消息数,具体可以获取的内容如下:
- 当前用户加入的所有超级群、指定超级群、或指定频道的未读消息数。
- 当前用户加入的所有超级群、指定超级群、或指定频道的未读 @ 消息数。
- 按免打扰级别获取总未读消息数。
- 返回的未读数最大值为 999,如果实际未读数超过 999,接口仍返 回 999。
提示
IMLib SDK 仅在 ChannelClient 中提供相关接口的调用。
获取多个超级群的未读消息数
SDK 支持获取当前用户加入的所有超级群中未读消息数与未读 @ 消息数。
批量获取当前用户的超级群的未读消息数
提示
IMLib SDK 从 5.4.6 版本开始支持此功能。
在社群应用场景中,如果您需要实时显示用户所在的多个超级群下所有频道的最新未读消息数据,您可以使用 getUltraGroupConversationUnreadInfoList 一次获取最多 20 个超级群下所有频道的未读数据。具体包含:
- 超级群频道的未读消息数
- 超级群频道的未读 @ 消息数
- 超级群频道中仅 @ 当前用户的未读 @ 消息数
- 超级群频道的免打扰级别
接口原型
Objective C
- (void)getUltraGroupConversationUnreadInfoList:(nonnull NSArray<NSString *> *)targetIds
success:(nonnull void (^)(NSArray<RCConversationUnreadInfo *> *list))successBlock
error:(nonnull void (^)(RCErrorCode status))errorBlock;
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
targetIds | NSString | 超级群会话 targetId 的列表,最多 20 个。 |
successBlock | Block | 查询未读信息的成功的回调,返回 RCConversationUnreadInfo 数组,包含会话中的未读消息数量、@ 消息的总个数、@ 我的消息的个数、免打扰级别等参数。 |
errorBlock | Block | 查询消息数量失败的回调。 |
示例代码
Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupConversationUnreadInfoList:targetIds success:^(NSArray<RCConversationUnreadInfo *> * _Nonnull list) {
for (RCConversationUnreadInfo *info in list) {
NSString *content = [NSString stringWithFormat:@"%@ %@:%@,%@,%@,%@", info.targetId, info.channelId, @(info.unreadMessageCount), @(info.mentionedCount), @(info.mentionedMeCount), @(info.notificationLevel)];
NSLog(@"%@", content);
}
} error:^(RCErrorCode status) {
// TODO error code
}];
获取当前用户加入的所有超级群未读消息数总和
接口原型
Objective C
- (void)getUltraGroupAllUnreadCount:(void (^)(NSInteger count))successBlock
error:(void (^)(RCErrorCode status))errorBlock;
参数说明
| 参数 | 类型 | 说明 |
|---|
| successBlock | Block | 查询未读信息的成功的回调,返回未读消息 的数量。 |
| errorBlock | Block | 查询消息数量失败的回调。 |
示例代码
Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupAllUnreadCount:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];
获取当前用户加入的所有超级群会话中的未读 @ 消息数的总和
接口原型
Objective C
- (void)getUltraGroupAllUnreadMentionedCount:(void (^)(NSInteger count))successBlock
error:(void (^)(RCErrorCode status))errorBlock;
参数说明
| 参数 | 类型 | 说明 |
|---|
| successBlock | Block | 查询未读 @ 消息数量的成功的回调,返回未读 @ 消息的数量。 |
| errorBlock | Block | 查询消息数量失败的回调。 |
示例代码
Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupAllUnreadMentionedCount:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];
获取指定超级群或频道中的未读消息数和未读 @ 消息数
获取指定单个超级群下所有频道的未读消息数
Objective C
- (void)getUltraGroupUnreadCount:(NSString *)targetId
success:(void (^)(NSInteger count))successBlock
error:(void (^)(RCErrorCode status))errorBlock
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
targetId | NSString | 超级群 targetId。 |
successBlock | Block | 查询未读消息数量的成功的回调,返回未读消息的数量。 |
errorBlock | Block | 查询消息数量失败的回调。 |
示例代码
Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadCount:@"targetId" success:^(NSInteger count) {
} error:^(RCErrorCode status) {
}];
获取指定单个超级群的未读 @ 消息数
接口原型
Objective C
- (void)getUltraGroupUnreadMentionedCount:(NSString *)targetId
completion:(nullable void(^)(int num))completion;
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
targetId | NSString | 超级群 targetId。 |
completion | Block | 查询未读 @ 消息数量的回调。 |
示例代码
Objective C
[[RCChannelClient sharedChannelManager] getUltraGroupUnreadMentionedCount:@"targetId" completion:^(int num) {
}];
获取超级群会话指定频道的未读消息数
Objective C
- (void)getUnreadCount:(RCConversationType)conversationType
targetId:(NSString *)targetId
channelId:(nullable NSString *)channelId
completion:(nullable void(^)(int num))completion;