其中有一个扩张消息类的方法:
+ (EMMessage *)sendTextMessage:(NSString *)text
to:(NSString *)toUser
messageType:(EMChatType)messageType
messageExt:(NSDictionary *)messageExt;
在该方法中将你要赋予的用户头像和昵称进行赋值。(这里可以用登录时拿到的用户头像和昵称)
如下:
+ (EMMessage *)sendTextMessage:(NSString *)text
to:(NSString *)toUser
messageType:(EMChatType)messageType
messageExt:(NSDictionary *)messageExt
{
NSString *willSendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:text];
EMTextMessageBody *body = [[EMTextMessageBody alloc] initWithText:willSendText];
NSString *from = [[EMClient sharedClient] currentUsername];
//开始 设置 扩展类消息
NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
[dic setValue:userDic[@"username"] forKey:@"username"];
[dic setValue:userDic[@"userHeadImg"] forKey:@"userHeadImg"];
[dic setValue:userDic[@"userid"] forKey:@"userid"];
[dic setValue:userDic[@"phonenum"] forKey:@"phonenum"];
for (NSString *key in messageExt.allKeys) {
[dic setValue:messageExt[key] forKey:key];
}
EMMessage *message = [[EMMessage alloc] initWithConversationID:toUser from:from to:toUser body:body ext:[dic copy]];
// 结束
// EMMessage *message = [[EMMessage alloc] initWithConversationID:toUser from:from to:toUser body:body ext:messageExt];
message.chatType = messageType;
return message;
}
除此方法外: 发送语音、位置、图片的扩展消息中也需设置头像和昵称。
网友评论