美文网首页
基于环信用户头像与昵称的集成

基于环信用户头像与昵称的集成

作者: 呆小萌28 | 来源:发表于2017-12-19 09:17 被阅读0次

    其中有一个扩张消息类的方法:

    + (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;

    }

    除此方法外: 发送语音、位置、图片的扩展消息中也需设置头像和昵称。

    相关文章

      网友评论

          本文标题:基于环信用户头像与昵称的集成

          本文链接:https://www.haomeiwen.com/subject/zqxbwxtx.html