@@ -19,6 +19,10 @@ @interface NoticeViewController ()<NIMUserManagerDelegate,NIMSystemNotificationM
1919
2020@implementation NoticeViewController
2121
22+ - (void )dealloc {
23+ NSLog (@" NoticeViewController----dealloc" );
24+ }
25+
2226+(instancetype )initWithNoticeViewController {
2327 static NoticeViewController *notVC = nil ;
2428 static dispatch_once_t onceToken;
@@ -34,7 +38,7 @@ -(void)initWithDelegate{
3438 _notifications = [NSMutableArray array ];
3539 [self setAllread ];
3640 id <NIMSystemNotificationManager> systemNotificationManager = [[NIMSDK sharedSDK ] systemNotificationManager ];
37- [systemNotificationManager addDelegate: self ];
41+ [systemNotificationManager addDelegate: nil ];
3842
3943 NSArray *notifications = [systemNotificationManager fetchSystemNotifications: nil
4044 limit: MaxNotificationCount];
@@ -72,10 +76,12 @@ -(void)initWithDelegate{
7276}
7377-(void )ReFrash {
7478 id <NIMSystemNotificationManager> systemNotificationManager = [[NIMSDK sharedSDK ] systemNotificationManager ];
75-
79+ [systemNotificationManager addDelegate: self ];
7680 NSArray *Secnotifications = [systemNotificationManager fetchSystemNotifications: nil
7781 limit: MaxNotificationCount];
78- if (Secnotifications.count ){
82+
83+
84+
7985 [_notiArr removeAllObjects ];
8086 [_notifications removeAllObjects ];
8187 [_notifications addObjectsFromArray: Secnotifications];
@@ -84,23 +90,33 @@ -(void)ReFrash{
8490 [self updateSourceMember: sourceMember andNoti: notices];
8591 }
8692 [self refrash ];
87- }
93+
8894}
8995
9096
9197- (void )stopSystemMsg {
92- [[[NIMSDK sharedSDK ] systemNotificationManager ] removeDelegate: self ];
98+ // [[[NIMSDK sharedSDK] systemNotificationManager] removeDelegate:self];
9399 [[[NIMSDK sharedSDK ] userManager ] removeDelegate: self ];
94100}
95101#pragma mark - NIMSDK Delegate
96102- (void )onSystemNotificationCountChanged : (NSInteger )unreadCount
97103{
98104 NIMModel *mode = [NIMModel initShareMD ];
99105 mode.unreadCount = unreadCount;
100-
106+ NSLog ( @" 2-----------unreadCount: %zd " ,unreadCount);
101107
102108}
103109- (void )onReceiveSystemNotification : (NIMSystemNotification *)notification {
110+ NSLog (@" 2----notification:%@ " ,notification);
111+ if (notification.type == NIMSystemNotificationTypeFriendAdd) {
112+ NIMUserAddAttachment *attach = notification.attachment ;
113+ NSLog (@" 2------attach.type:%zd " ,attach.operationType );
114+ if (attach.operationType == NIMUserOperationVerify) {// 如果是通过添加好友请求,标为已读并删除
115+ [[NIMSDK sharedSDK ].systemNotificationManager markNotificationsAsRead: notification];
116+ [[[NIMSDK sharedSDK ] systemNotificationManager ] deleteNotification: notification];
117+ }
118+ }
119+
104120
105121 if (_notifications.count ) {
106122 for (NIMSystemNotification *notices in _notifications) {
@@ -221,7 +237,6 @@ - (void)loadMore:(id)sender
221237}
222238// 删除信息
223239-(void )deleteNotice : (NSString *)targetID timestamp : (NSString *)timestamp {
224-
225240 for (int i = 0 ; i < _notifications.count ; i++) {
226241 NIMSystemNotification *notices =_notifications[i];
227242 if ([targetID isEqualToString: notices.sourceID]) {
@@ -424,12 +439,12 @@ -(void)onRefuse:(NSString *)targetID timestamp:(NSString *)timestamp sucess:(Suc
424439 completion: ^(NSError *error) {
425440 if (!error) {
426441
427- notices.handleStatus = NotificationHandleTypeNo;
428- [_notifications replaceObjectAtIndex: i withObject: notices];
429- for (NIMSystemNotification *notices in _notifications) {
430- NIMKitInfo *sourceMember = [[NIMKit sharedKit ] infoByUser: notices.sourceID option: nil ];
431- [self updateSourceMember: sourceMember andNoti: notices];
432- }
442+ // notices.handleStatus = NotificationHandleTypeNo;
443+ // [_notifications replaceObjectAtIndex:i withObject:notices];
444+ // for (NIMSystemNotification *notices in _notifications) {
445+ // NIMKitInfo *sourceMember = [[NIMKit sharedKit] infoByUser:notices.sourceID option:nil];
446+ // [self updateSourceMember:sourceMember andNoti:notices];
447+ // }
433448 success (@" 拒绝成功" );
434449
435450 }
0 commit comments