Skip to content

Commit c92d164

Browse files
guangyaoguangyao
authored andcommitted
增加推送消息内容
1 parent dea56d8 commit c92d164

File tree

5 files changed

+97
-47
lines changed

5 files changed

+97
-47
lines changed

ios/RNNeteaseIm/RNNeteaseIm/ConversationViewController.m

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -363,29 +363,19 @@ - (void)stopPlay{
363363
//发送录音
364364
-(void)sendAudioMessage:( NSString *)file duration:( NSString *)duration{
365365
if (file) {
366-
[[[NIMSDK sharedSDK] chatManager] sendMessage:[NIMMessageMaker msgWithAudio:file] toSession:_session error:nil];
366+
[[[NIMSDK sharedSDK] chatManager] sendMessage:[NIMMessageMaker msgWithAudio:file andeSession:_session] toSession:_session error:nil];
367367
}
368368
}
369369
//发送文字消息
370370
-(void)sendMessage:(NSString *)mess andApnsMembers:(NSArray *)members{
371-
NIMMessage *message = [[NIMMessage alloc] init];
372-
message.text = mess;
373-
message.apnsContent = mess;
374-
if (members.count) {
375-
NIMMessageApnsMemberOption *apnsMemberOption = [[NIMMessageApnsMemberOption alloc]init];
376-
apnsMemberOption.userIds = members;
377-
apnsMemberOption.forcePush = YES;
378-
apnsMemberOption.apnsContent = @"有人@了你";
379-
message.apnsMemberOption = apnsMemberOption;
380-
}
381-
message.apnsContent = mess;
371+
NIMMessage *message = [NIMMessageMaker msgWithText:mess andApnsMembers:members andeSession:_session];
382372
//发送消息
383373
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
384374
}
385375
//发送图片
386376
-(void)sendImageMessages:( NSString *)path displayName:( NSString *)displayName{
387377
UIImage *img = [[UIImage alloc]initWithContentsOfFile:path];
388-
NIMMessage *message = [NIMMessageMaker msgWithImage:img];
378+
NIMMessage *message = [NIMMessageMaker msgWithImage:img andeSession:_session];
389379
// NIMMessage *message = [NIMMessageMaker msgWithImagePath:path];
390380
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
391381
}
@@ -396,7 +386,7 @@ -(void)sendTextMessage:( NSString *)path duration:( NSString *)duration width:
396386
// if (image) {
397387
// message = [NIMMessageMaker msgWithImage:image];
398388
// }else{
399-
message = [NIMMessageMaker msgWithVideo:path];
389+
message = [NIMMessageMaker msgWithVideo:path andeSession:_session];
400390
// }
401391
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
402392

@@ -407,15 +397,15 @@ -(void)sendCustomMessage:( NSString *)attachment config:( NSString *)config{
407397
NIMMessage *message;
408398
NIMObject *obj = [NIMObject initNIMObject];
409399
obj.attachment =attachment;
410-
message = [NIMMessageMaker msgWithCustom:obj];
400+
message = [NIMMessageMaker msgWithCustom:obj andeSession:_session];
411401
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
412402
}
413403

414404
//发送地理位置消息
415405
-(void)sendLocationMessage:( NSString *)latitude longitude:( NSString *)longitude address:( NSString *)address{
416406
NIMLocationObject *locaObj = [[NIMLocationObject alloc]initWithLatitude:[latitude doubleValue] longitude:[longitude doubleValue] title:address];
417407
NIMKitLocationPoint *locationPoint = [[NIMKitLocationPoint alloc]initWithLocationObject:locaObj];
418-
NIMMessage *message = [NIMMessageMaker msgWithLocation:locationPoint];
408+
NIMMessage *message = [NIMMessageMaker msgWithLocation:locationPoint andeSession:_session];
419409
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
420410
}
421411
//发送自定义消息2
@@ -424,7 +414,7 @@ -(void)sendCustomMessage:(NSInteger )custType data:(NSDictionary *)dataDict{
424414
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
425415
obj.custType = custType;
426416
obj.dataDict = dataDict;
427-
message = [NIMMessageMaker msgWithCustomAttachment:obj];
417+
message = [NIMMessageMaker msgWithCustomAttachment:obj andeSession:_session];
428418
[[NIMSDK sharedSDK].chatManager sendMessage:message toSession:_session error:nil];
429419
}
430420

@@ -459,7 +449,7 @@ -(void)sendRedPacketOpenMessage:(NSString *)sendId hasRedPacket:(NSString *)hasR
459449
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
460450
obj.custType = CustomMessgeTypeRedPacketOpenMessage;
461451
obj.dataDict = dict;
462-
message = [NIMMessageMaker msgWithCustomAttachment:obj];
452+
message = [NIMMessageMaker msgWithCustomAttachment:obj andeSession:_session];
463453
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
464454
message.timestamp = timestamp;
465455
if(![sendId isEqualToString:strMyId]){
@@ -653,7 +643,7 @@ - (void)recordAudio:(NSString *)filePath didBeganWithError:(NSError *)error {
653643
- (void)recordAudio:(NSString *)filePath didCompletedWithError:(NSError *)error {
654644
if(!error) {
655645
if ([self recordFileCanBeSend:filePath]) {
656-
[[[NIMSDK sharedSDK] chatManager] sendMessage:[NIMMessageMaker msgWithAudio:filePath] toSession:_session error:nil];
646+
[[[NIMSDK sharedSDK] chatManager] sendMessage:[NIMMessageMaker msgWithAudio:filePath andeSession:_session] toSession:_session error:nil];
657647
}else{
658648
[self showRecordFileNotSendReason];
659649
}

ios/RNNeteaseIm/RNNeteaseIm/RNNeteaseIm.m

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,44 @@ - (instancetype)init{
2727

2828
- (void)clickObserveNotification:(NSNotification *)noti{
2929
NSDictionary *dict = noti.object;
30-
NSDictionary *param = [dict objectForKey:@"dict"];
31-
if ([[dict objectForKey:@"type"] isEqualToString:@"launch"]) {
32-
[_bridge.eventDispatcher sendDeviceEventWithName:@"observeLaunchPushEvent" body:param];
33-
}else{
34-
[_bridge.eventDispatcher sendDeviceEventWithName:@"observeBackgroundPushEvent" body:param];
30+
NSMutableDictionary *param = [NSMutableDictionary dictionaryWithDictionary:[dict objectForKey:@"dict"]];
31+
NSString *strDict = [param objectForKey:@"sessionBody"];
32+
if ([strDict length]) {
33+
NSDictionary *dataDict = [self dictChangeFromJson:strDict];
34+
NSMutableDictionary *mutaDict = [NSMutableDictionary dictionaryWithDictionary:dataDict];
35+
NSString *strType = [mutaDict objectForKey:@"sessionType"];
36+
NSString *strSessionId = [mutaDict objectForKey:@"sessionId"];
37+
NSString *strSessionName = @"";
38+
if ([strType isEqualToString:@"0"]) {//点对点
39+
NIMUser *user = [[NIMSDK sharedSDK].userManager userInfo:strSessionId];
40+
if ([user.alias length]) {
41+
strSessionName = user.alias;
42+
}else{
43+
NIMUserInfo *userInfo = user.userInfo;
44+
strSessionName = userInfo.nickName;
45+
}
46+
}else{//群主
47+
NIMTeam *team = [[[NIMSDK sharedSDK] teamManager]teamById:strSessionId];
48+
strSessionName = team.teamName;
49+
}
50+
[mutaDict setObject:strSessionName forKey:@"sessionName"];
51+
[param setObject:mutaDict forKey:@"sessionBody"];
52+
if ([[dict objectForKey:@"type"] isEqualToString:@"launch"]) {
53+
[_bridge.eventDispatcher sendDeviceEventWithName:@"observeLaunchPushEvent" body:param];
54+
}else{
55+
[_bridge.eventDispatcher sendDeviceEventWithName:@"observeBackgroundPushEvent" body:param];
56+
}
3557
}
58+
3659
}
3760

61+
- (NSDictionary *)dictChangeFromJson:(NSString *)strJson{
62+
NSData* data = [strJson dataUsingEncoding:NSUTF8StringEncoding];
63+
__autoreleasing NSError* error = nil;
64+
id result = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
65+
if (error != nil) return nil;
66+
return result;
67+
}
3868

3969
@synthesize bridge = _bridge;
4070
- (dispatch_queue_t)methodQueue

ios/RNNeteaseIm/RNNeteaseIm/RNNotificationCenter.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ - (void)saveTheRedPacketOpenMsg:(NSDictionary *)dict andTime:(NSTimeInterval)tim
147147
DWCustomAttachment *obj = [[DWCustomAttachment alloc]init];
148148
obj.custType = CustomMessgeTypeRedPacketOpenMessage;
149149
obj.dataDict = datatDict;
150-
message = [NIMMessageMaker msgWithCustomAttachment:obj];
150+
message = [NIMMessageMaker msgWithCustomAttachment:obj andeSession:session];
151151
message.timestamp = timestamp;
152152
[[NIMSDK sharedSDK].conversationManager saveMessage:message forSession:session completion:nil];
153153
}

ios/RNNeteaseIm/RNNeteaseIm/Util/NIMMessageMaker.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,20 @@
1313

1414
@interface NIMMessageMaker : NSObject
1515

16-
+ (NIMMessage*)msgWithText:(NSString*)text;
16+
+ (NIMMessage*)msgWithText:(NSString*)text andApnsMembers:(NSArray *)members andeSession:(NIMSession *)session;
1717

18-
+ (NIMMessage *)msgWithAudio:(NSString *)filePath;
18+
+ (NIMMessage *)msgWithAudio:(NSString *)filePath andeSession:(NIMSession *)session;
1919

20-
+ (NIMMessage *)msgWithImage:(UIImage *)image;
20+
+ (NIMMessage *)msgWithImage:(UIImage *)image andeSession:(NIMSession *)session;
2121

22-
+ (NIMMessage *)msgWithImagePath:(NSString *)path;
22+
+ (NIMMessage *)msgWithImagePath:(NSString *)path andeSession:(NIMSession *)session;
2323

24-
+ (NIMMessage *)msgWithVideo:(NSString *)filePath;
24+
+ (NIMMessage *)msgWithVideo:(NSString *)filePath andeSession:(NIMSession *)session;
2525

26-
+ (NIMMessage *)msgWithLocation:(NIMKitLocationPoint*)locationPoint;
26+
+ (NIMMessage *)msgWithLocation:(NIMKitLocationPoint*)locationPoint andeSession:(NIMSession *)session;
2727

28-
+ (NIMMessage*)msgWithCustom:(NIMObject *)attachment;
28+
+ (NIMMessage*)msgWithCustom:(NIMObject *)attachment andeSession:(NIMSession *)session;
29+
30+
+ (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment andeSession:(NIMSession *)session;
2931

30-
+ (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment;
3132
@end

ios/RNNeteaseIm/RNNeteaseIm/Util/NIMMessageMaker.m

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,45 @@
1212

1313
@implementation NIMMessageMaker
1414

15-
+ (NIMMessage*)msgWithText:(NSString*)text
15+
+ (NIMMessage*)msgWithText:(NSString*)text andApnsMembers:(NSArray *)members andeSession:(NIMSession *)session
1616
{
17-
NIMMessage *textMessage = [[NIMMessage alloc] init];
18-
textMessage.text = text;
19-
return textMessage;
17+
18+
NIMMessage *message = [[NIMMessage alloc] init];
19+
message.text = text;
20+
message.apnsContent = text;
21+
if (members.count) {
22+
NIMMessageApnsMemberOption *apnsMemberOption = [[NIMMessageApnsMemberOption alloc]init];
23+
apnsMemberOption.userIds = members;
24+
apnsMemberOption.forcePush = YES;
25+
apnsMemberOption.apnsContent = @"有人@了你";
26+
message.apnsMemberOption = apnsMemberOption;
27+
}
28+
message.apnsContent = text;
29+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
30+
return message;
2031
}
2132

22-
+ (NIMMessage*)msgWithAudio:(NSString*)filePath
33+
+ (NIMMessage*)msgWithAudio:(NSString*)filePath andeSession:(NIMSession *)session
2334
{
2435
NIMAudioObject *audioObject = [[NIMAudioObject alloc] initWithSourcePath:filePath];
2536
NIMMessage *message = [[NIMMessage alloc] init];
2637
message.messageObject = audioObject;
2738
message.text = @"发来了一段语音";
39+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
2840
return message;
2941
}
30-
+ (NIMMessage*)msgWithCustom:(NIMObject *)attachment
42+
+ (NIMMessage*)msgWithCustom:(NIMObject *)attachment andeSession:(NIMSession *)session
3143
{
3244

3345
NIMMessage *message = [[NIMMessage alloc] init];
3446
NIMCustomObject *customObject = [[NIMCustomObject alloc] init];
3547
customObject.attachment = attachment;
3648
message.messageObject = customObject;
3749
message.apnsContent = @"发来了一条未知消息";
50+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
3851
return message;
3952
}
40-
+ (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment
53+
+ (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment andeSession:(NIMSession *)session
4154
{
4255

4356
NIMMessage *message = [[NIMMessage alloc] init];
@@ -71,10 +84,11 @@ + (NIMMessage*)msgWithCustomAttachment:(DWCustomAttachment *)attachment
7184
break;
7285
}
7386
message.apnsContent = text;
87+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
7488
return message;
7589
}
7690

77-
+ (NIMMessage*)msgWithVideo:(NSString*)filePath
91+
+ (NIMMessage*)msgWithVideo:(NSString*)filePath andeSession:(NIMSession *)session
7892
{
7993
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
8094
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
@@ -84,18 +98,19 @@ + (NIMMessage*)msgWithVideo:(NSString*)filePath
8498
NIMMessage *message = [[NIMMessage alloc] init];
8599
message.messageObject = videoObject;
86100
message.apnsContent = @"发来了一段视频";
101+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
87102
return message;
88103
}
89-
+ (NIMMessage*)msgWithImage:(UIImage*)image
104+
+ (NIMMessage*)msgWithImage:(UIImage*)image andeSession:(NIMSession *)session
90105
{
91106
NIMImageObject *imageObject = [[NIMImageObject alloc] initWithImage:image];
92107
NIMImageOption *option = [[NIMImageOption alloc] init];
93108
option.compressQuality = 0.7;
94109
imageObject.option = option;
95-
return [NIMMessageMaker generateImageMessage:imageObject];
110+
return [NIMMessageMaker generateImageMessage:imageObject andeSession:session];
96111
}
97112

98-
+ (NIMMessage *)msgWithImagePath:(NSString*)path
113+
+ (NIMMessage *)msgWithImagePath:(NSString*)path andeSession:(NIMSession *)session
99114
{
100115
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
101116
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
@@ -105,10 +120,10 @@ + (NIMMessage *)msgWithImagePath:(NSString*)path
105120
NIMMessage *message = [[NIMMessage alloc] init];
106121
message.messageObject = imageObject;
107122
message.apnsContent = @"发来了一张图片";
108-
return [NIMMessageMaker generateImageMessage:imageObject];
123+
return [NIMMessageMaker generateImageMessage:imageObject andeSession:session];
109124
}
110125

111-
+ (NIMMessage *)generateImageMessage:(NIMImageObject *)imageObject
126+
+ (NIMMessage *)generateImageMessage:(NIMImageObject *)imageObject andeSession:(NIMSession *)session
112127
{
113128
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
114129
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
@@ -117,19 +132,33 @@ + (NIMMessage *)generateImageMessage:(NIMImageObject *)imageObject
117132
NIMMessage *message = [[NIMMessage alloc] init];
118133
message.messageObject = imageObject;
119134
message.apnsContent = @"发来了一张图片";
135+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
120136
return message;
121137
}
122138

123139

124-
+ (NIMMessage*)msgWithLocation:(NIMKitLocationPoint *)locationPoint{
140+
+ (NIMMessage*)msgWithLocation:(NIMKitLocationPoint *)locationPoint andeSession:(NIMSession *)session{
125141
NIMLocationObject *locationObject = [[NIMLocationObject alloc] initWithLatitude:locationPoint.coordinate.latitude
126142
longitude:locationPoint.coordinate.longitude
127143
title:locationPoint.title];
128144
NIMMessage *message = [[NIMMessage alloc] init];
129145
message.messageObject = locationObject;
130146
message.apnsContent = @"发来了一条位置信息";
147+
[NIMMessageMaker setupMessagePushBody:message andSession:session];
131148
return message;
132149
}
133150

151+
+ (void)setupMessagePushBody:(NIMMessage *)message andSession:(NIMSession *)session{
152+
NSMutableDictionary *payload = [NSMutableDictionary dictionary];
153+
NSString *strSessionID = @"";
154+
if (session.sessionType == NIMSessionTypeP2P) {//点对点
155+
strSessionID = [NIMSDK sharedSDK].loginManager.currentAccount;
156+
}else{
157+
strSessionID = [NSString stringWithFormat:@"%@",session.sessionId];
158+
}
159+
NSString *strSessionType = [NSString stringWithFormat:@"%zd",session.sessionType];
160+
[payload setObject:@{@"sessionId":strSessionID,@"sessionType":strSessionType} forKey:@"sessionBody"];
161+
message.apnsPayload = payload;
162+
}
134163

135164
@end

0 commit comments

Comments
 (0)