日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

菜鸟搞环信

發(fā)布時(shí)間:2025/3/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 菜鸟搞环信 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

剛完成了環(huán)信的相關(guān)工作,剛好有時(shí)間來(lái)寫(xiě)一下關(guān)于環(huán)信的東西

馬上進(jìn)入主題吧

?

1.關(guān)于如何集成環(huán)信。

  集成環(huán)信的話(huà)就不多說(shuō)了

2.如何修改環(huán)信的昵稱(chēng)和頭像。

  這個(gè)我認(rèn)為是重點(diǎn)。我也是一個(gè)新手,都是一步一個(gè)腳印,慢慢踩踏過(guò)來(lái)的。

  我的做法是分兩個(gè),一個(gè)是利用環(huán)信的ext擴(kuò)展作為突破口。第二個(gè)是利用本地緩存作為突破口。

  首先說(shuō)一下,為什么有兩個(gè)?

  因?yàn)?#xff0c;我們?cè)诎l(fā)消息的時(shí)候,可以利用環(huán)信的ext擴(kuò)展,把頭像之類(lèi)的東西,存到消息里面。這樣,我們?cè)诎l(fā)消息的時(shí)候就可以獲得頭像之類(lèi)的東西,然后就可以更新chatview。這個(gè)僅僅作用于發(fā)消息。在我們接收到一條新消息的時(shí)候,就不能這么搞了。因?yàn)?#xff0c;如果你之前沒(méi)有發(fā)送過(guò)消息給他,那么你的ext擴(kuò)展就不能穿過(guò)去給他。這樣就會(huì)造成只有你發(fā)過(guò)消息的人才能正常顯示。這里就需要用到本地緩存了。

  大致的思路就這樣,那么我們就分散一步一步來(lái)~~

?

A。首先把單聊發(fā)消息的這個(gè)給先實(shí)現(xiàn)。

從這里push到環(huán)信的會(huì)話(huà)列表。push之前安全起見(jiàn),先本地化頭像。。

- (void)pushToChatViewController{

? ? /// 新建一個(gè)會(huì)話(huà)

? ? if ([self.model.user_no isEqualToString:[UserInfo shareUserInfo].user_no]) {

? ? ? ? [MBProgressHUD showAndDismissInWindow:@"不能與自己聊天"];

? ? ? ? return;

? ? }

? ? NSString *name = self.model.user_niname;

? ? if (name.length == 0 || [name isEqualToString:@""]) {

? ? ? ? name = @"xx";

? ? }

? ? //TODO:這里我只是為了測(cè)試

? ? NSString *img = self.model.user_headimg;

? ? if (img.length == 0 || [img isEqualToString:@""]) {

? ? ? ? img = @"";

? ? }

?? ?

? ? //保存用戶(hù)的昵稱(chēng)和頭像到數(shù)據(jù)庫(kù)

? ? MCNickNameDB *nickNameDB = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",name]];

? ? if (nickNameDB) {

? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? n.conversationId = self.userId;

? ? ? ? n.niname = name;

? ? ? ? n.headimg = img;

? ? ? ? BOOL nick = [nickNameDB.niname isEqualToString:n.niname];

? ? ? ? BOOL img = [nickNameDB.headimg isEqualToString:n.headimg];

? ? ? ? if (!nick || !img) {

? ? ? ? ? ? [MCNickNameDB deleteObjectsByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",n.conversationId]];

? ? ? ? ? ? [n save];

? ? ? ? ? ? MCNickNameDB *nickNameDB2 = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",n.conversationId]];

? ? ? ? ? ? DLog(@"%@",nickNameDB2);

? ? ? ? }

?? ? ? ?

? ? }else{

? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? n.conversationId = self.userId;

? ? ? ? n.niname = name;

? ? ? ? n.headimg = img;

? ? ? ? [n save];

? ? }

?? ?

? ? NSDictionary *ext = @{

? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Nicname_Other_Key:name,

? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Avatar_Other_Key:img

? ? ? ? ? ? ? ? ? ? ? ? ? };

? ? ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:_userId conversationType:EMConversationTypeChat ext:ext];

? ? DLog(@"新建一個(gè)會(huì)話(huà) ext == %@ ",ext);

? ? chatController.title = _model.user_niname;

? ? [self.navigationController pushViewController:chatController animated:YES];

}

  既然是發(fā)消息,那么久肯定跟EaseChatToolbar輸入框有關(guān)了

  找到EaseChatToolbar ?

- (void)sendFaceWithEmotion:(EaseEmotion *)emotion{

  if (emotion) {

? ? ? ?  if ([self.delegate respondsToSelector:@selector(didSendText:withExt:)]) {

? ? ? ? ? ?  NSString *name = EASE_Nik_Name_Value;

? ? ? ? ? ?  NSString *img = EASE_Avatar_Value;

? ? ? ? ? ?  if ([name isEqualToString:@""] || name.length == 0) {

? ? ? ? ? ? ? ? ?name = EASE_Nik_Name_Def;

? ? ? ? ? ? }

? ? ? ? ? ? if ([img isEqualToString:@""] || img.length == 0) {

? ? ? ? ? ? ? ? img = EASE_Avatar_Def;

? ? ? ? ? ? }

? ? ? ? ? ? /// ?兔斯基表情文本擴(kuò)展

? ? ? ? ? ? NSDictionary *ext = @{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EASEUI_EMOTION_DEFAULT_EXT:emotion,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Avatar_Key:img,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Nik_Name_Key:name

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? };

? ? ? ? ? ? [self.delegate didSendText:emotion.emotionTitle withExt:ext];

? ? ? ? ? ? [self _willShowInputTextViewToHeight:[self _getTextViewContentH:self.inputTextView]];;

? ? ? ? }

? ? }

?

      }      

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{

if ([text isEqualToString:@"\n"]) {

? ? ? ? if ([self.delegate respondsToSelector:@selector(didSendText:)]) {

? ? ? ? ? ? NSString *name = EASE_Nik_Name_Value;

? ? ? ? ? ? NSString *img = EASE_Avatar_Value;

? ? ? ? ? ? if ([name isEqualToString:@""] || name.length == 0) {

? ? ? ? ? ? ? ? name = EASE_Nik_Name_Def;

? ? ? ? ? ? }

? ? ? ? ? ? if ([img isEqualToString:@""] || img.length == 0) {

? ? ? ? ? ? ? ? img = EASE_Avatar_Def;

? ? ? ? ? ? }

? ? ? ? ? ?NSDictionary *ext = @{

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Avatar_Key:img,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? EASE_Nik_Name_Key:name

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? };

? ? ? ? ? ? [self.delegate didSendText:textView.text withExt:ext];

? ? ? ? ? ? //結(jié)束

? ? ? ? ? ? self.inputTextView.text = @"";

? ? ? ? ? ? [self _willShowInputTextViewToHeight:[self _getTextViewContentH:self.inputTextView]];

? ? ? ? }

? ? ? ? return NO;

? ? }

? ? else if ([text isEqualToString:@"@"]) {

? ? ? ? if ([self.delegate respondsToSelector:@selector(didInputAtInLocation:)]) {

? ? ? ? ? ? if ([self.delegate didInputAtInLocation:range.location]) {

? ? ? ? ? ? ? ? [self _willShowInputTextViewToHeight:[self _getTextViewContentH:self.inputTextView]];

? ? ? ? ? ? ? ? return NO;

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? else if ([text length] == 0) {

? ? ? ? //delete one character

? ? ? ? if (range.length == 1 && [self.delegate respondsToSelector:@selector(didDeleteCharacterFromLocation:)]) {

? ? ? ? ? ? return ![self.delegate didDeleteCharacterFromLocation:range.location];

? ? ? ? }

? ? }

? ? return YES;

?

}

        

  在這兩個(gè)方法上面 ,添加ext。。其實(shí)細(xì)心的人可以發(fā)現(xiàn)EaseChatToolbar的delegate是EaseMessageViewController

  所以也可以

  我比較建議在EaseMessageViewController,因?yàn)椴还苁裁搭?lèi)型的消息都是走這個(gè)類(lèi)的

?

  代碼如下

 

- (void)didSendText:(NSString *)text withExt:(NSDictionary*)ext

{

? ? //TODO:這里是不包括 add的?

? ? DLog(@"消息的攜帶體是ext == %@",ext);

? ? DLog(@"img == %@, name == %@",ext[EASE_Avatar_Key],ext[EASE_Nik_Name_Def]);

? ? NSMutableDictionary *dic = [NSMutableDictionary dictionary];

? ? dic[EASE_Avatar_Key] = ext[EASE_Avatar_Key];

? ? dic[EASE_Nik_Name_Def] = ext[EASE_Nik_Name_Def];

? ? DLog(@"conversation == %@",_conversation.conversationId);

? ? if (self.conversation.type == 1) {/// 群聊

? ? ? ? MCNickNameDB *nickNameDB = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",_conversation.conversationId]];

? ? ? ? dic[EASE_GroupID__Key] = nickNameDB.conversationId;

? ? ? ? dic[EASE_Nicname_Group_Key] = nickNameDB.niname;

? ? ? ? dic[EASE_Avatar_Group_Key] = nickNameDB.headimg;

? ? ? ? DLog(@"EASE_GroupID__Key == %@",dic[EASE_Nicname_Group_Key]);

? ? }

?? ?

?? ?

? ? if ([ext objectForKey:EASEUI_EMOTION_DEFAULT_EXT]) {

? ? ? ? EaseEmotion *emotion = [ext objectForKey:EASEUI_EMOTION_DEFAULT_EXT];

? ? ? ? if (self.dataSource && [self.dataSource respondsToSelector:@selector(emotionExtFormessageViewController:easeEmotion:)]) {

? ? ? ? ? ? /// 這里是純兔斯基 發(fā)送 ?

? ? ? ? ? ? NSDictionary *emojiDic = [self.dataSource emotionExtFormessageViewController:self easeEmotion:emotion];

? ? ? ? ? ? if (self.conversation.type == 1) {/// 群聊

? ? ? ? ? ? ? ? dic[@"em_expression_id"] = emojiDic[@"em_expression_id"];

? ? ? ? ? ? ? ? dic[@"em_is_big_expression"] = emojiDic[@"em_is_big_expression"];

? ? ? ? ? ? }

?? ? ? ? ? ?

? ? ? ? ? ? [self sendTextMessage:emotion.emotionTitle withExt:dic];

? ? ? ? } else {

? ? ? ? ? ? // 這里需要加上消息擴(kuò)張

? ? ? ? ? ? if (self.conversation.type == 0) {

? ? ? ? ? ? ? ? [self sendTextMessage:emotion.emotionTitle withExt:

?? ? ? ? ? ? ? ? @{

?? ? ? ? ? ? ? ? ? MESSAGE_ATTR_EXPRESSION_ID:emotion.emotionId,MESSAGE_ATTR_IS_BIG_EXPRESSION:@(YES),

?? ? ? ? ? ? ? ? ? EASE_Avatar_Key:dic[EASE_Avatar_Key],

?? ? ? ? ? ? ? ? ? EASE_Nik_Name_Key:dic[EASE_Nik_Name_Key]

?? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ?

?? ? ? ? ? ? ? ? ];

? ? ? ? ? ? }else{/// 群聊

? ? ? ? ? ? ? ? [self sendTextMessage:emotion.emotionTitle withExt:

?? ? ? ? ? ? ? ? @{

?? ? ? ? ? ? ? ? ? MESSAGE_ATTR_EXPRESSION_ID:emotion.emotionId,MESSAGE_ATTR_IS_BIG_EXPRESSION:@(YES),

?? ? ? ? ? ? ? ? ? EASE_Avatar_Key:dic[EASE_Avatar_Key],

?? ? ? ? ? ? ? ? ? EASE_Nik_Name_Key:dic[EASE_Nik_Name_Key],

?? ? ? ? ? ? ? ? ? EASE_Avatar_Group_Key:dic[EASE_Avatar_Group_Key],

?? ? ? ? ? ? ? ? ? EASE_Nicname_Group_Key:dic[EASE_Nicname_Group_Key],

?? ? ? ? ? ? ? ? ? EASE_GroupID__Key:dic[EASE_GroupID__Key]

?? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ?

?? ? ? ? ? ? ? ? ];

? ? ? ? ? ? }

?? ? ? ? ? ?

? ? ? ? }

? ? ? ? return;

? ? }

? ? if (text && text.length > 0) {

? ? ? ? /// 純文字副本發(fā)送 ? ?

? ? ? ? if (self.conversation.type == 0) {?

? ? ? ? ? ? [self sendTextMessage:text withExt:ext];

? ? ? ? }else{/// 群聊

? ? ? ? ? ? [self sendTextMessage:text withExt:dic];

? ? ? ? }

?? ? ? ?

? ? }

}

?

以上標(biāo)有群聊的可以先忽略不做

在所有發(fā)消息的(兔斯基,表情,文字,表情+文字等等)統(tǒng)統(tǒng)加上ext

例如

- (void)sendTextMessage:(NSString *)text

{

? ? // NSDictionary *ext = nil;

? ? /// 在這里添加emoji 頭像?

? ? NSString *name = EASE_Nik_Name_Value;

? ? NSString *img = EASE_Avatar_Value;

? ? if ([name isEqualToString:@""] || name.length == 0) {

? ? ? ? name = EASE_Nik_Name_Def;

? ? }

? ? if ([img isEqualToString:@""] || img.length == 0) {

? ? ? ? img = EASE_Avatar_Def;

? ? }

?? ?

? ? NSMutableDictionary *ext = [NSMutableDictionary dictionary];

? ? ext[EASE_Avatar_Key] = img;

? ? ext[EASE_Nik_Name_Key] = name;

?? ?

? ? if (self.conversation.type == 1) {//群聊

? ? ? ? MCNickNameDB *nickNameDB = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",_conversation.conversationId]];

? ? ? ? ext[EASE_GroupID__Key] = nickNameDB.conversationId;

? ? ? ? ext[EASE_Nicname_Group_Key] = nickNameDB.niname;

? ? ? ? ext[EASE_Avatar_Group_Key] = nickNameDB.headimg;

? ? ? ? DLog(@"EASE_GroupID__Key == %@",ext[EASE_Nicname_Group_Key]);

? ? }

? ? if (self.conversation.type == EMConversationTypeGroupChat) {

? ? ? ? NSArray *targets = [self _searchAtTargets:text];

? ? ? ? if ([targets count]) {

? ? ? ? ? ? __block BOOL atAll = NO;

? ? ? ? ? ? [targets enumerateObjectsUsingBlock:^(NSString *target, NSUInteger idx, BOOL *stop) {

? ? ? ? ? ? ? ? if ([target compare:kGroupMessageAtAll options:NSCaseInsensitiveSearch] == NSOrderedSame) {

? ? ? ? ? ? ? ? ? ? atAll = YES;

? ? ? ? ? ? ? ? ? ? *stop = YES;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }];

? ? ? ? ? ? if (atAll) {

? ? ? ? ? ? ? ? ext = @{kGroupMessageAtList: kGroupMessageAtAll};

? ? ? ? ? ? }

? ? ? ? ? ? else {

? ? ? ? ? ? ? ? ext = @{kGroupMessageAtList: targets};

? ? ? ? ? ? }

? ? ? ? }

? ? }

? ? [self sendTextMessage:text withExt:ext];

}

?

那么,所有的消息都帶上了ext,基本上發(fā)消息的就完成了。

回到chatViewController里面

- (NSDictionary*)emotionExtFormessageViewController:(EaseMessageViewController *)viewController

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? easeEmotion:(EaseEmotion*)easeEmotion{

? ? /// ?兔斯基表情文本擴(kuò)展

? ? NSString *name = EASE_Nik_Name_Value;

? ? NSString *img = EASE_Avatar_Value;

? ? if ([name isEqualToString:@""] || name.length == 0) {

? ? ? ? name = EASE_Nik_Name_Def;

? ? }

? ? if ([img isEqualToString:@""] || img.length == 0) {

? ? ? ? img = EASE_Avatar_Def;

? ? }

? ? return @{

?? ? ? ? ? ? MESSAGE_ATTR_EXPRESSION_ID:easeEmotion.emotionId,MESSAGE_ATTR_IS_BIG_EXPRESSION:@(YES),

?? ? ? ? ? ? EASE_Avatar_Key:img,

?? ? ? ? ? ? EASE_Nik_Name_Key:name

?? ? ? ? ? ? };

}

?

- (id<IMessageModel>)messageViewController:(EaseMessageViewController *)viewController

?? ? ? ? ? ? ? ? ? ? ? ? ? modelForMessage:(EMMessage *)message{

? ? id<IMessageModel> model = nil;

? ? model = [[EaseMessageModel alloc] initWithMessage:message];

? ? //TODO:這里設(shè)置環(huán)信的頭像

? ? NSDictionary *dic? = message.ext;

? ? NSString *userName = dic[EASE_Nik_Name_Key];

? ? NSString *sendUserImg = dic[EASE_Avatar_Key];

? ? model.avatarURLPath = sendUserImg;

? ? model.nickname = userName;

? ? UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:model.nickname];

? ? if (profileEntity) {

? ? ? ? model.avatarURLPath = profileEntity.imageUrl;

? ? ? ? model.nickname = profileEntity.nickname;

? ? }

? ? model.failImageName = @"imageDownloadFail";

? ? return model;

}

?

這樣發(fā)消息就ok了。。。

下面就說(shuō)一下接收消息,接收消息我用本地緩存。

接收消息的話(huà),就找chatdemohelper

找到

/// 這里好重要 ? 就是收到消息擴(kuò)張?

- (void)didReceiveMessages:(NSArray *)aMessages

{

? ? //保存用戶(hù)的昵稱(chēng)和頭像到數(shù)據(jù)庫(kù)

? ? BOOL isRefreshCons = YES;

? ? for(EMMessage *message in aMessages){

?? ? ? ?

? ? ? ? DLog(@"EMChatType == %d? ext == %@",message.chatType,message.ext);

?? ? ? ?

? ? ? ? if (message.chatType == 0) { // 單聊

? ? ? ? ? ? //保存用戶(hù)的昵稱(chēng)和頭像到數(shù)據(jù)庫(kù)

? ? ? ? ? ? MCNickNameDB *nickNameDB = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",message.conversationId]];

? ? ? ? ? ? if (nickNameDB) {

? ? ? ? ? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? ? ? ? ? n.conversationId = message.conversationId;

? ? ? ? ? ? ? ? n.niname = message.ext[EASE_Nik_Name_Key];

? ? ? ? ? ? ? ? n.headimg = message.ext[EASE_Avatar_Key];

? ? ? ? ? ? ? ? BOOL nick = [nickNameDB.niname isEqualToString:n.niname];

? ? ? ? ? ? ? ? BOOL img = [nickNameDB.headimg isEqualToString:n.headimg];

? ? ? ? ? ? ? ? if (!nick || !img) {

? ? ? ? ? ? ? ? ? ? [MCNickNameDB deleteObjectsByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",message.conversationId]];

? ? ? ? ? ? ? ? ? ? [n save];

? ? ? ? ? ? ? ? ? ? MCNickNameDB *nickNameDB2 = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",message.conversationId]];

? ? ? ? ? ? ? ? ? ? DLog(@"%@",nickNameDB2);

? ? ? ? ? ? ? ? }

?? ? ? ? ? ? ? ?

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? ? ? ? ? n.conversationId = message.conversationId;

? ? ? ? ? ? ? ? n.niname = message.ext[EASE_Nik_Name_Key];

? ? ? ? ? ? ? ? n.headimg = message.ext[EASE_Avatar_Key];

? ? ? ? ? ? ? ? [n save];

? ? ? ? ? ? }

? ? ? ? }else{ //TODO: 聊天時(shí) 群聊

? ? ? ? ? ? //保存群聊的昵稱(chēng)和頭像到數(shù)據(jù)庫(kù)

? ? ? ? ? ? NSDictionary *ext = message.ext;

? ? ? ? ? ? MCNickNameDB *nickNameDB = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",message.conversationId]];

? ? ? ? ? ? if (nickNameDB) {

? ? ? ? ? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? ? ? ? ? n.conversationId = ext[EASE_GroupID__Key];

? ? ? ? ? ? ? ? n.niname = ext[EASE_Nicname_Group_Key];

? ? ? ? ? ? ? ? n.headimg = ext[EASE_Avatar_Group_Key];

? ? ? ? ? ? ? ? BOOL nick = [nickNameDB.niname isEqualToString:n.niname];

? ? ? ? ? ? ? ? BOOL img = [nickNameDB.headimg isEqualToString:n.headimg];

? ? ? ? ? ? ? ? if (!nick || !img) {

? ? ? ? ? ? ? ? ? ? [MCNickNameDB deleteObjectsByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",n.conversationId]];

? ? ? ? ? ? ? ? ? ? [n save];

? ? ? ? ? ? ? ? ? ? MCNickNameDB *nickNameDB2 = [MCNickNameDB findFirstByCriteria:[NSString stringWithFormat:@" WHERE conversationId = %@ ",n.conversationId]];

? ? ? ? ? ? ? ? ? ? DLog(@"%@",nickNameDB2);

? ? ? ? ? ? ? ? }

?? ? ? ? ? ? ? ?

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? MCNickNameDB *n = [MCNickNameDB new];

? ? ? ? ? ? ? ? n.conversationId = ext[EASE_GroupID__Key];

? ? ? ? ? ? ? ? n.niname = ext[EASE_Nicname_Group_Key];;

? ? ? ? ? ? ? ? n.headimg = ext[EASE_Avatar_Group_Key];

? ? ? ? ? ? ? ? [n save];

? ? ? ? ? ? }

?

?? ? ? ? ? ?

? ? ? ? }

? ? ? ? BOOL needShowNotification = (message.chatType != EMChatTypeChat) ? [self _needShowNotification:message.conversationId] : YES;

?? ? ? ?

#ifdef REDPACKET_AVALABLE

? ? ? ? /**

?? ? ? ? *? 屏蔽紅包被搶消息的提示

?? ? ? ? */

? ? ? ? NSDictionary *dict = message.ext;

? ? ? ? needShowNotification = (dict && [dict valueForKey:RedpacketKeyRedpacketTakenMessageSign]) ? NO : needShowNotification;

#endif

?? ? ? ?

? ? ? ? UIApplicationState state = [[UIApplication sharedApplication] applicationState];

? ? ? ? if (needShowNotification) {

#if !TARGET_IPHONE_SIMULATOR

? ? ? ? ? ? switch (state) {

? ? ? ? ? ? ? ? case UIApplicationStateActive:

? ? ? ? ? ? ? ? ? ? [self.mainVC playSoundAndVibration];

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case UIApplicationStateInactive:

? ? ? ? ? ? ? ? ? ? [self.mainVC playSoundAndVibration];

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? case UIApplicationStateBackground:

? ? ? ? ? ? ? ? ? ? [self.mainVC showNotificationWithMessage:message];

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? default:

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

#endif

? ? ? ? }

?? ? ? ?

? ? ? ? if (_chatVC == nil) {

? ? ? ? ? ? _chatVC = [self _getCurrentChatView];

? ? ? ? }

? ? ? ? BOOL isChatting = NO;

? ? ? ? if (_chatVC) {

? ? ? ? ? ? isChatting = [message.conversationId isEqualToString:_chatVC.conversation.conversationId];

? ? ? ? }

? ? ? ? if (_chatVC == nil || !isChatting || state == UIApplicationStateBackground) {

? ? ? ? ? ? [self _handleReceivedAtMessage:message];

?? ? ? ? ? ?

? ? ? ? ? ? if (self.conversationListVC) {

? ? ? ? ? ? ? ? [_conversationListVC refresh];

? ? ? ? ? ? }

?? ? ? ? ? ?

? ? ? ? ? ? if (self.mainVC) {

? ? ? ? ? ? ? ? [_mainVC setupUnreadMessageCount];

? ? ? ? ? ? }

? ? ? ? ? ? return;

? ? ? ? }

?? ? ? ?

? ? ? ? if (isChatting) {

? ? ? ? ? ? isRefreshCons = NO;

? ? ? ? }

? ? }

?? ?

? ? if (isRefreshCons) {

? ? ? ? if (self.conversationListVC) {

? ? ? ? ? ? [_conversationListVC refresh];

? ? ? ? }

?? ? ? ?

? ? ? ? if (self.mainVC) {

? ? ? ? ? ? [_mainVC setupUnreadMessageCount];

? ? ? ? }

? ? }

}

?

以上,,單聊的基本完成。。。。如果有遺漏,請(qǐng)留言,,

下面是群聊

其實(shí)群聊跟單聊是一樣,,不過(guò),就是給ext擴(kuò)展再添加一個(gè)群的名稱(chēng),一個(gè)群的頭像。

然后在拿屬性的時(shí)候,劃分一下是群聊還是單聊。。。

這里就不一一到來(lái),上面有標(biāo)注群聊的大家可以看一下~~~

?

轉(zhuǎn)載于:https://www.cnblogs.com/LusYoHo/p/6371249.html

總結(jié)

以上是生活随笔為你收集整理的菜鸟搞环信的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。