Skip to content

Commit 59e9189

Browse files
committed
Merge branch 'master' of github.com:reactnativecomponent/react-native-netease-im
2 parents 1aa2d44 + 504c571 commit 59e9189

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ContactViewController.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,12 @@ -(void)adduserId:(NSString *)userId andVerifyType:(NSString *)strType andMag:(NS
335335
- (void)sendCustomNotificationContent:(NSString *)content andSessionID:(NSString *)sessionID andApnsContent:(NSString *)strApns AndData:(NSDictionary *)dict{
336336
NIMSession *session = [NIMSession session:sessionID type:NIMSessionTypeP2P];
337337
NIMCustomSystemNotification *notifi = [[NIMCustomSystemNotification alloc]initWithContent:content];
338+
NIMCustomSystemNotificationSetting *setting = [[NIMCustomSystemNotificationSetting alloc]init];
339+
setting.apnsEnabled = YES;
338340
notifi.apnsContent = strApns;
339341
notifi.apnsPayload = dict;
342+
notifi.sendToOnlineUsersOnly = NO;
343+
notifi.setting = setting;
340344
[[NIMSDK sharedSDK].systemNotificationManager sendCustomNotification:notifi toSession:session completion:nil];//发送自定义通知
341345
}
342346

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.m

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,26 @@ - (void)sendBankTransferMessage:(NSString *)amount comments:(NSString *)comments
424424
-(void)sendRedPacketOpenMessage:(NSString *)sendId hasRedPacket:(NSString *)hasRedPacket serialNo:(NSString *)serialNo{
425425
NSString *strMyId = [NIMSDK sharedSDK].loginManager.currentAccount;
426426
NSDictionary *dict = @{@"sendId":sendId,@"openId":strMyId,@"hasRedPacket":hasRedPacket,@"serialNo":serialNo};
427-
[self sendCustomMessage:CustomMessgeTypeRedPacketOpenMessage data:dict];
428-
427+
NIMMessage *message;
428+
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
429+
obj.custType = CustomMessgeTypeRedPacketOpenMessage;
430+
obj.dataDict = dict;
431+
message = [NIMMessageMaker msgWithCustomAttachment:obj];
432+
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
433+
message.timestamp = timestamp;
434+
if(![sendId isEqualToString:strMyId]){
435+
NSDictionary *dataDict = @{@"type":@"2",@"data":@{@"dict":dict,@"timestamp":[NSString stringWithFormat:@"%f",timestamp],@"sessionId":_session.sessionId,@"sessionType":[NSString stringWithFormat:@"%zd",_session.sessionType]}};
436+
NIMSession *redSession = [NIMSession session:sendId type:NIMSessionTypeP2P];
437+
NIMCustomSystemNotification *notifi = [[NIMCustomSystemNotification alloc]initWithContent:@""];
438+
notifi.sendToOnlineUsersOnly = NO;
439+
NIMCustomSystemNotificationSetting *setting = [[NIMCustomSystemNotificationSetting alloc]init];
440+
setting.shouldBeCounted = NO;
441+
setting.apnsEnabled = NO;
442+
notifi.setting = setting;
443+
notifi.apnsPayload = dataDict;
444+
[[NIMSDK sharedSDK].systemNotificationManager sendCustomNotification:notifi toSession:redSession completion:nil];//发送自定义通知
445+
}
446+
[[NIMSDK sharedSDK].conversationManager saveMessage:message forSession:_session completion:nil];
429447
}
430448

431449

ios/RNNeteaseIm/RNNeteaseIm/RNNotificationCenter.m

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#import "RNNotificationCenter.h"
1010
#import <AVFoundation/AVFoundation.h>
1111
#import "NSDictionary+NTESJson.h"
12+
#import "NIMMessageMaker.h"
1213
@interface RNNotificationCenter () <NIMSystemNotificationManagerDelegate,NIMChatManagerDelegate>
1314
@property (nonatomic,strong) AVAudioPlayer *player; //播放提示音
1415
@end
@@ -84,15 +85,39 @@ - (void)checkMessageAt:(NSArray *)messages
8485

8586
#pragma mark - NIMSystemNotificationManagerDelegate
8687
- (void)onReceiveCustomSystemNotification:(NIMCustomSystemNotification *)notification{//接收自定义通知
87-
88-
NSString *content = notification.content;
88+
// NSString *content = notification.content;
8989
NSDictionary *notiDict = notification.apnsPayload;
9090
if (notiDict){
91-
if ([[notiDict objectForKey:@"type"] integerValue]==1) {//加好友
92-
91+
NSInteger notiType = [[notiDict objectForKey:@"type"] integerValue];
92+
switch (notiType) {
93+
case 1://加好友
94+
95+
break;
96+
case 2://拆红包消息
97+
{
98+
[self saveTheRedPacketOpenMsg:[notiDict objectForKey:@"data"]];
99+
}
100+
break;
101+
102+
default:
103+
break;
93104
}
94105
}
95106
}
96-
107+
//保存拆红包消息到本地
108+
- (void)saveTheRedPacketOpenMsg:(NSDictionary *)dict{
109+
NSDictionary *datatDict = [dict objectForKey:@"dict"];
110+
NSTimeInterval timestamp = [[dict objectForKey:@"timestamp"] doubleValue];
111+
NSString *sessionId = [dict objectForKey:@"sessionId"];
112+
NSInteger sessionType = [[dict objectForKey:@"sessionType"] integerValue];
113+
NIMSession *session = [NIMSession session:sessionId type:sessionType];
114+
NIMMessage *message;
115+
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
116+
obj.custType = CustomMessgeTypeRedPacketOpenMessage;
117+
obj.dataDict = datatDict;
118+
message = [NIMMessageMaker msgWithCustomAttachment:obj];
119+
message.timestamp = timestamp;
120+
[[NIMSDK sharedSDK].conversationManager saveMessage:message forSession:session completion:nil];
121+
}
97122

98123
@end

0 commit comments

Comments
 (0)