@@ -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