Skip to content

Commit e4e8059

Browse files
guangyaoguangyao
authored andcommitted
Fix 加好友通知崩溃的问题,add 过滤通过好友请求通知
1 parent caa3bfc commit e4e8059

File tree

3 files changed

+31
-33
lines changed

3 files changed

+31
-33
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ContactViewController.m

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ -(void)initWithDelegate{
4040
_specialGroups = [[NSMutableOrderedSet alloc] init];
4141
_groupTtiles = [[NSMutableOrderedSet alloc] init];
4242
_groups = [[NSMutableOrderedSet alloc] init];
43-
[[[NIMSDK sharedSDK] systemNotificationManager] addDelegate:self];
43+
// [[[NIMSDK sharedSDK] systemNotificationManager] addDelegate:self];
4444
[[[NIMSDK sharedSDK] userManager] addDelegate:self];
4545

4646
// id<NIMSystemNotificationManager> systemNotificationManager = [[NIMSDK sharedSDK] systemNotificationManager];
@@ -353,17 +353,6 @@ - (void)onLogin:(NIMLoginStep)step
353353
}
354354
}
355355

356-
#pragma mark - NIMSDK Delegate
357-
- (void)onSystemNotificationCountChanged:(NSInteger)unreadCount//加好友未读条数
358-
{
359-
NIMModel *mode = [NIMModel initShareMD];
360-
mode.unreadCount = unreadCount;
361-
NSLog(@"-----------unreadCount:%zd",unreadCount);
362-
}
363-
364-
- (void)onReceiveSystemNotification:(NIMSystemNotification *)notification{
365-
NSLog(@"----notification:%@",notification);
366-
}
367356

368357
- (void)onUserInfoChanged:(NIMUser *)user
369358
{

ios/RNNeteaseIm/RNNeteaseIm/NIMModel.m

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,24 @@ -(void)setNIMKick:(NSString *)NIMKick{
4545
}
4646
}
4747
-(void)setContactList:(NSMutableDictionary *)contactList{
48-
if ((_contactList != contactList)&&(contactList.count)) {
48+
if (_contactList != contactList) {
4949
_contactList = contactList;
5050
self.myBlock(3, contactList);
5151
}
5252
}
5353
-(void)setNotiArr:(NSMutableArray *)notiArr{
54-
if (notiArr.count) {
5554
self.myBlock(5, notiArr);
56-
}
5755
}
5856
-(void)setTeamArr:(NSMutableArray *)teamArr{
59-
if (teamArr.count) {
6057
self.myBlock(4, teamArr);
61-
}
6258
}
6359
//未读条数
6460
-(void)setUnreadCount:(NSInteger)unreadCount{
6561
self.myBlock(6, [NSString stringWithFormat:@"%ld",unreadCount]);
6662
}
6763
//
6864
-(void)setResorcesArr:(NSMutableArray *)ResorcesArr{
69-
if (ResorcesArr.count) {
7065
self.myBlock(7, ResorcesArr);
71-
}
7266
}
7367
//开始发送
7468
-(void)setStartSend:(NSDictionary *)startSend{
@@ -96,7 +90,7 @@ -(void)setReceipt:(NSString *)receipt{
9690
}
9791
//发送消息
9892
-(void)setSendState:(NSMutableArray *)sendState{
99-
if ((_sendState != sendState)&&(sendState.count)) {
93+
if (_sendState != sendState) {
10094
self.myBlock(12, sendState);
10195
}
10296
}

ios/RNNeteaseIm/RNNeteaseIm/NoticeViewController.m

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)