Skip to content

Commit 087d88d

Browse files
guangyaoguangyao
authored andcommitted
Fix红包提醒
1 parent 07fb89a commit 087d88d

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.m

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,10 @@ -(void)sendRedPacketOpenMessage:(NSString *)sendId hasRedPacket:(NSString *)hasR
444444
message.timestamp = timestamp;
445445
if(![sendId isEqualToString:strMyId]){
446446
NSDictionary *dataDict = @{@"type":@"2",@"data":@{@"dict":dict,@"timestamp":[NSString stringWithFormat:@"%f",timestamp],@"sessionId":_session.sessionId,@"sessionType":[NSString stringWithFormat:@"%zd",_session.sessionType]}};
447+
448+
NSString *content = [self jsonStringWithDictionary:dataDict];
447449
NIMSession *redSession = [NIMSession session:sendId type:NIMSessionTypeP2P];
448-
NIMCustomSystemNotification *notifi = [[NIMCustomSystemNotification alloc]initWithContent:@""];
450+
NIMCustomSystemNotification *notifi = [[NIMCustomSystemNotification alloc]initWithContent:content];
449451
notifi.sendToOnlineUsersOnly = NO;
450452
NIMCustomSystemNotificationSetting *setting = [[NIMCustomSystemNotificationSetting alloc]init];
451453
setting.shouldBeCounted = NO;
@@ -455,8 +457,23 @@ -(void)sendRedPacketOpenMessage:(NSString *)sendId hasRedPacket:(NSString *)hasR
455457
[[NIMSDK sharedSDK].systemNotificationManager sendCustomNotification:notifi toSession:redSession completion:nil];//发送自定义通知
456458
}
457459
[[NIMSDK sharedSDK].conversationManager saveMessage:message forSession:_session completion:nil];
460+
458461
}
459462

463+
// dict字典转json字符串
464+
- (NSString *)jsonStringWithDictionary:(NSDictionary *)dict
465+
{
466+
if (dict && 0 != dict.count)
467+
{
468+
NSError *error = nil;
469+
// NSJSONWritingOptions 是"NSJSONWritingPrettyPrinted"的话有换位符\n;是"0"的话没有换位符\n。
470+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:&error];
471+
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
472+
return jsonString;
473+
}
474+
475+
return nil;
476+
}
460477

461478

462479
//设置好友消息提醒
@@ -520,7 +537,10 @@ - (void)onRecvMessages:(NSArray *)messages
520537
completion:nil];
521538
//标记已读消息
522539
[[NIMSDK sharedSDK].conversationManager markAllMessagesReadInSession:_session];
523-
[self playTipsMusicWithMessage:message];
540+
541+
if (![message.from isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) {
542+
[self playTipsMusicWithMessage:message];
543+
}
524544
}
525545
}
526546

ios/RNNeteaseIm/RNNeteaseIm/NIMViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ - (NSString *)messageContent:(NIMMessage*)lastMessage{
302302
default:
303303
text = @"[未知消息]";
304304
}
305-
if (lastMessage.session.sessionType == NIMSessionTypeP2P || lastMessage.messageType == NIMMessageTypeTip || lastMessage.messageType == NIMMessageTypeCustom) {
305+
if ((lastMessage.session.sessionType == NIMSessionTypeP2P) || (lastMessage.messageType == NIMMessageTypeTip)||([lastMessage.from isEqualToString:[NIMSDK sharedSDK].loginManager.currentAccount]) ) {
306306
return text;
307307
}else{
308308
NSString *nickName = [NIMKitUtil showNick:lastMessage.from inSession:lastMessage.session];

ios/RNNeteaseIm/RNNeteaseIm/RNNotificationCenter.m

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ - (void)checkMessageAt:(NSArray *)messages
8787
#pragma mark - NIMSystemNotificationManagerDelegate
8888
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification{//接收自定义通知
8989
// NSString *content = notification.content;
90-
NSDictionary *notiDict = notification.apnsPayload;
90+
NSDictionary *notiDict = [self jsonDictWithString:notification.content];
91+
NSTimeInterval timestamp = notification.timestamp;
9192
if (notiDict){
9293
NSInteger notiType = [[notiDict objectForKey:@"type"] integerValue];
9394
switch (notiType) {
@@ -96,7 +97,7 @@ - (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notific
9697
break;
9798
case 2://拆红包消息
9899
{
99-
[self saveTheRedPacketOpenMsg:[notiDict objectForKey:@"data"]];
100+
[self saveTheRedPacketOpenMsg:[notiDict objectForKey:@"data"] andTime:timestamp];
100101
}
101102
break;
102103

@@ -106,9 +107,9 @@ - (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notific
106107
}
107108
}
108109
//保存拆红包消息到本地
109-
- (void)saveTheRedPacketOpenMsg:(NSDictionary *)dict{
110+
- (void)saveTheRedPacketOpenMsg:(NSDictionary *)dict andTime:(NSTimeInterval)times{
110111
NSDictionary *datatDict = [dict objectForKey:@"dict"];
111-
NSTimeInterval timestamp = [[dict objectForKey:@"timestamp"] doubleValue];
112+
NSTimeInterval timestamp = times;
112113
NSString *sessionId = [dict objectForKey:@"sessionId"];
113114
NSInteger sessionType = [[dict objectForKey:@"sessionType"] integerValue];
114115
if (sessionType == NIMSessionTypeP2P) {//点对点
@@ -124,4 +125,22 @@ - (void)saveTheRedPacketOpenMsg:(NSDictionary *)dict{
124125
[[NIMSDK sharedSDK].conversationManager saveMessage:message forSession:session completion:nil];
125126
}
126127

128+
// json字符串转dict字典
129+
- (NSDictionary *)jsonDictWithString:(NSString *)string
130+
{
131+
if (string && 0 != string.length)
132+
{
133+
NSError *error;
134+
NSData *jsonData = [string dataUsingEncoding:NSUTF8StringEncoding];
135+
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
136+
if (error)
137+
{
138+
NSLog(@"json解析失败:%@", error);
139+
return nil;
140+
}
141+
return jsonDict;
142+
}
143+
return nil;
144+
}
145+
127146
@end

0 commit comments

Comments
 (0)