但是,融云在发送自定义消息时,用户的头像,昵称不会根据之前赋值而携带发送.所以要在自定义消息里面添加上用户信息.
#import "RCDTestMessage.h"
@implementation RCDTestMessage
///将消息内容编码成json
- (NSData*)encode{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
if (self.senderUserInfo) {
NSMutableDictionary *__dic = [[NSMutableDictionary alloc] init];
if (self.senderUserInfo.name) {
[__dicsetObject:self.senderUserInfo.nameforKeyedSubscript:@"name"];
}
if (self.senderUserInfo.portraitUri) {
[__dicsetObject:self.senderUserInfo.portraitUriforKeyedSubscript:@"portrait"];
}
if (self.senderUserInfo.userId) {
[__dicsetObject:self.senderUserInfo.userIdforKeyedSubscript:@"id"];
}
[dicsetObject:__dicforKey:@"user"];
}
NSData *data = [NSJSONSerialization dataWithJSONObject:dic
options:kNilOptions
error:nil];
returndata;
}
///将json解码生成消息内容
- (void)decodeWithData:(NSData*)data {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
if(dic) {
NSDictionary*userinfoDic = [dicobjectForKey:@"user"];
[selfdecodeUserInfo:userinfoDic];
}
}
- (NSArray<NSString *> *)getSearchableWords {
return nil;
}
+ (RCMessagePersistent)persistentFlag {
return MessagePersistent_ISPERSISTED;
}
+ (NSString *)getObjectName {
return RCDTestMessageTypeIdentifier;
}
@end
然后在发送自定义消息的时候,再赋一次值.就可以将用户信息一起发送出去了.
网友评论