系统通知
[TOC]
概述
除消息通道外,SDK 还提供系统通知这种通道用于消息之外的通知分发。目前有两种类型:内置系统通知和自定义系统通知。 现在主要包括群变动的相关通知,例如入群申请,入群邀请等,如果第三方应用还托管了好友关系,好友的添加、删除也是这个类型的通知。系统通知由 SDK 负责接收和存储,并提供较简单的未读数管理。
内置系统通知
内置系统通知由 QDSystemNotification
表示。
原型
@interface QDSystemNotification : NSObject
/**
* 通知 ID
*/
@property (nonatomic, strong, readonly) NSString *notificationId;
/**
* 通知类型
*/
@property (nonatomic, assign, readonly) QDSystemNotificationType type;
/**
* 时间戳
*/
@property (nonatomic, assign, readonly) NSTimeInterval timestamp;
/**
* 操作者ID
*/
@property (nullable,nonatomic,copy,readonly) NSString *sourceID;
/**
* 操作者名称
*/
@property (nullable,nonatomic,copy,readonly) NSString *sourceName;
/**
* 目标ID,群ID或者是用户ID
*/
@property (nullable,nonatomic,copy,readonly) NSString *targetID;
/**
* 附言
*/
@property (nullable,nonatomic,copy,readonly) NSString *postscript;
/**
* 是否已读
*/
@property (nonatomic, assign) BOOL isRead;
/**
* 消息处理状态
* @discussion 修改这个属性,后台会自动更新 db 中对应的数据,SDK 调用者可以使用这个值来持久化他们对消息的处理结果,默认为 0
*/
@property (nonatomic, assign) NSInteger handleStatus;
/**
* 附件
* @discussion 额外信息,只有 好友添加 这个通知有附件
* 好友添加的 attachment 为 QDUserAddAttachment
*/
@property (nullable,nonatomic,strong,readonly)id attachment;
@end
所有的内置系统通知都是通过
@protocol QDSystemNotificationManagerDelegate <NSObject>
@optional
/**
收到系统通知回调
@param notification 系统通知
*/
- (void)onReceiveSystemNotification:(QDSystemNotification *)notification;
@end
内置系统通知的本地存储:(以下接口分为全量和过滤,过滤接口需要传入过滤器 QDSystemNotificationFilter,可以按类型选择获取内置系统通知)
QDSystemNotificationFilter
原型
@interface QDSystemNotificationFilter : NSObject
/**
* 类型列表,取值范围为: QDSystemNotificationType 枚举类型
*/
@property (nonatomic, copy) NSArray<NSNumber *> *notificationTypes;
@end
获取本地存储的内置系统通知
- 全量接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
获取本地存储的系统通知
@param notification 当前最早系统消息,没有则传入nil
@param limit 最大获取数
@return 系统消息列表
*/
- (nullable NSArray<QDSystemNotification *> *)fetchSystemNotifications:(nullable QDSystemNotification *)notification limit:(NSInteger)limit;
@end
- 过滤接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
获取本地存储的系统通知
@param notification 当前最早系统消息,没有则传入nil
@param limit 最大获取数
@param filter 过滤器
@return 系统消息列表
*/
- (nullable NSArray<QDSystemNotification *> *)fetchSystemNotifications:(nullable QDSystemNotification *)notification
limit:(NSInteger)limit
filter:(nullable QDSystemNotificationFilter *)filter;
@end
获取本地存储的内置系统未读数
- 全量接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
未读系统消息数
@return 未读系统消息数
*/
- (NSInteger)allUnreadCount;
@end
- 过滤接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
未读系统消息数
@param filter 过滤器
@return 未读系统消息数
*/
- (NSInteger)allUnreadCount:(nullable QDSystemNotificationFilter *)filter;
@end
删除本地存储的内置系统通知
- 全量接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
删除所有系统消息
*/
- (void)deleteAllNotifications;
@end
- 过滤接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
删除所有命中过滤器的系统消息
@param filter 过滤器
*/
- (void)deleteAllNotifications:(nullable QDSystemNotificationFilter *)filter;
@end
- 单条接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
删除单条系统消息
@param notification 系统消息
*/
- (void)deleteNotification:(QDSystemNotification *)notification;
@end
标记本地存储的内置系统通知为已读
- 全量接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
标记所有系统消息为已读
*/
- (void)markAllNotificationsAsRead;
@end
- 过滤接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
标记所有命中过滤器的系统消息为已读
@param filter 过滤器
*/
- (void)markAllNotificationsAsRead:(nullable QDSystemNotificationFilter *)filter;
@end
- 单条接口
@protocol QDIMSystemNotificationManager <NSObject>
/**
标记单条系统消息为已读
@param notification 系统消息
*/
- (void)markNotificationsAsRead:(QDSystemNotification *)notification;
@end