http://www.jianshu.com/p/f53be9664f14
注意:
最终效果
添加环信SDK
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import "EaseMob.h"
#endif /* PrefixHeader_pch */
添加环信EaseUI
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import "EaseMob.h"
#import "EaseUI.h"
#endif /* PrefixHeader_pch */
其中APPDelegate中文件内容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//注册SDK
[[EaseMob sharedInstance] registerSDKWithAppKey:@"easemob-demo#chatdemoui" apnsCertName:nil];
//注册UI
[[EaseSDKHelper shareHelper] easemobApplication:application
didFinishLaunchingWithOptions:launchOptions
appkey:@"easemob-demo#chatdemoui"
apnsCertName:nil
otherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];
[[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
return YES;
}
ViewController中的内容
- (IBAction)login:(id)sender {
//用户名:zlanchun 密码:123456
//异步登陆账号
[[EaseMob sharedInstance].chatManager asyncLoginWithUsername:@"zlanchun" password:@"123456" completion:^(NSDictionary *loginInfo, EMError *error) {
if (loginInfo && !error) {
//发送自动登陆状态通知
[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@YES];
} else {
NSLog(@"login error: %@",error);
}
} onQueue:nil];
}
- (void)jumpToChatVC {
//创建聊天室 对象:zlanchun1
EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];
[self.navigationController pushViewController:chatController animated:YES];
}
继承Demo3.0中的功能
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
//头文件
#import "ChatDemoUIDefine.h"
#import "EMAlertView.h"
#import "TTGlobalUICommon.h"
#import "UIViewController+DismissKeyboard.h"
#import "NSString+Valid.h"
#import "EaseMob.h"
#import "EaseUI.h"
#endif /* PrefixHeader_pch */
注释未引用的文件,删除重复引用的文件,添加第三方库Parse的依赖。
注释未引用的文件:
在ViewController.m中应用头文件#import "ChatViewController.h"
。然后在跳转方法中,注册跳转VC,跳转即可。
ViewController.m新增部分:
- (void)jumpToChatVC {
//创建聊天室 对象:zlanchun1
//EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];
//创建基于Demo3.0Class的chatroom
ChatViewController *chatController = [[ChatViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];
[self.navigationController pushViewController:chatController animated:YES];
}
ChatViewController.m中需要注释的地方
#import "ChatViewController.h"
//#import "ChatGroupDetailViewController.h"
//#import "ChatroomDetailViewController.h"
#import "CustomMessageCell.h"
//#import "UserProfileViewController.h"
//#import "UserProfileManager.h"
//#import "ContactListSelectViewController.h"
- (void)messageViewController:(EaseMessageViewController *)viewController
didSelectAvatarMessageModel:(id<IMessageModel>)messageModel
{
//UserProfileViewController *userprofile = [[UserProfileViewController alloc] initWithUsername:messageModel.nickname];
//[self.navigationController pushViewController:userprofile animated:YES];
}
- (id<IMessageModel>)messageViewController:(EaseMessageViewController *)viewController
modelForMessage:(EMMessage *)message
{
id<IMessageModel> model = nil;
model = [[EaseMessageModel alloc] initWithMessage:message];
model.avatarImage = [UIImage imageNamed:@"EaseUIResource.bundle/user"];
// UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:model.nickname];
// if (profileEntity) {
// model.avatarURLPath = profileEntity.imageUrl;
// }
model.failImageName = @"imageDownloadFail";
return model;
}
- (void)showGroupDetailAction
{
[self.view endEditing:YES];
// if (self.conversation.conversationType == eConversationTypeGroupChat) {
// ChatGroupDetailViewController *detailController = [[ChatGroupDetailViewController alloc] initWithGroupId:self.conversation.chatter];
// [self.navigationController pushViewController:detailController animated:YES];
// }
// else if (self.conversation.conversationType == eConversationTypeChatRoom)
// {
// ChatroomDetailViewController *detailController = [[ChatroomDetailViewController alloc] initWithChatroomId:self.conversation.chatter];
// [self.navigationController pushViewController:detailController animated:YES];
// }
}
- (void)transpondMenuAction:(id)sender
{
// if (self.menuIndexPath && self.menuIndexPath.row > 0) {
// id<IMessageModel> model = [self.dataArray objectAtIndex:self.menuIndexPath.row];
// ContactListSelectViewController *listViewController = [[ContactListSelectViewController alloc] initWithNibName:nil bundle:nil];
// listViewController.messageModel = model;
// [listViewController tableViewDidTriggerHeaderRefresh];
// [self.navigationController pushViewController:listViewController animated:YES];
// }
self.menuIndexPath = nil;
}
UIImageView+HeadImage.文件中注释
/************************************************************ * * EaseMob CONFIDENTIAL * __________________ * Copyright (C) 2013-2014 EaseMob Technologies. All rights reserved. * * NOTICE: All information contained herein is, and remains * the property of EaseMob Technologies. * Dissemination of this information or reproduction of this material * is strictly forbidden unless prior written permission is obtained * from EaseMob Technologies. */
#import "UIImageView+HeadImage.h"
//#import "UserProfileManager.h"
@implementation UIImageView (HeadImage)
- (void)imageWithUsername:(NSString *)username placeholderImage:(UIImage*)placeholderImage
{
if (placeholderImage == nil) {
placeholderImage = [UIImage imageNamed:@"chatListCellHead"];
}
// UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:username];
// if (profileEntity) {
// [self sd_setImageWithURL:[NSURL URLWithString:profileEntity.imageUrl] placeholderImage:placeholderImage];
// } else {
// [self sd_setImageWithURL:nil placeholderImage:placeholderImage];
// }
[self sd_setImageWithURL:nil placeholderImage:placeholderImage];
}
@end
@implementation UILabel (Prase)
- (void)setTextWithUsername:(NSString *)username
{
// UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:username];
// if (profileEntity) {
// if (profileEntity.nickname && profileEntity.nickname.length > 0) {
// [self setText:profileEntity.nickname];
// [self setNeedsLayout];
// } else {
// [self setText:username];
// }
// } else {
// [self setText:username];
// }
[self setText:username];
}
@end
添加parse依赖库:
删除重用引用MBProgressHUD库
删除wav.mm文件。
删除VoiceConvert文件
错误集合
报错1:未添加Parse依赖库引起的clang: error: linker command failed with exit code 1 (use -v to see invocation)
错误。
解决办法:添加parse的依赖库,一共有5个(环信小哥告诉我有4个,结果,添加完4个依赖后,9个错误变成4个了。咋办?还好有Google,查parse依赖关系,发现15年7月份依赖增加了一个。)
剩余的4个错误("_OBJC_CLASS_$_SKPayment"
):
看看国外小哥怎么说得(地址)。
报错2:删除重复引用MBProgressHUD库
报错3:删除重复引用wav.mm文件
报错4:删除VoiceConvert文件
Demo程序见:这里(百度云盘)