环信集成 2---基于环信Demo3.0,实现单聊功能
這幾天在做環(huán)信,所以把環(huán)信相關(guān)的東西拿過來,做個系統(tǒng)點的東西
?
?
注意:
最終效果
15
添加環(huán)信SDK
鏈接地址
1
2
3
在pch中,導(dǎo)入頭文件。 #ifndef PrefixHeader_pch #define PrefixHeader_pch #import "EaseMob.h" #endif /* PrefixHeader_pch */
4
添加環(huán)信EaseUI
找到Demo3.0的EaseUI目錄,然后將如下文件,拖拽到項目中。并在pch文件中引入EaseUI.h #ifndef PrefixHeader_pch #define PrefixHeader_pch #import "EaseMob.h" #import "EaseUI.h" #endif /* PrefixHeader_pch */
5
6
其中APPDelegate中文件內(nèi)容
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {//注冊SDK[[EaseMob sharedInstance] registerSDKWithAppKey:@"easemob-demo#chatdemoui" apnsCertName:nil];//注冊UI[[EaseSDKHelper shareHelper] easemobApplication:applicationdidFinishLaunchingWithOptions:launchOptionsappkey:@"easemob-demo#chatdemoui"apnsCertName:nilotherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];[[EaseMob sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];return YES; }ViewController中的內(nèi)容
- (IBAction)login:(id)sender {//用戶名:zlanchun 密碼:123456//異步登陸賬號[[EaseMob sharedInstance].chatManager asyncLoginWithUsername:@"zlanchun" password:@"123456" completion:^(NSDictionary *loginInfo, EMError *error) {if (loginInfo && !error) {//發(fā)送自動登陸狀態(tài)通知[[NSNotificationCenter defaultCenter] postNotificationName:KNOTIFICATION_LOGINCHANGE object:@YES];} else {NSLog(@"login error: %@",error);}} onQueue:nil]; }- (void)jumpToChatVC {//創(chuàng)建聊天室 對象:zlanchun1EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];[self.navigationController pushViewController:chatController animated:YES]; }繼承Demo3.0中的功能
7
8
9
注釋未引用的文件,刪除重復(fù)引用的文件,添加第三方庫Parse的依賴。
注釋未引用的文件:
在ViewController.m中應(yīng)用頭文件#import "ChatViewController.h"。然后在跳轉(zhuǎn)方法中,注冊跳轉(zhuǎn)VC,跳轉(zhuǎn)即可。
ViewController.m新增部分:
- (void)jumpToChatVC {//創(chuàng)建聊天室 對象:zlanchun1//EaseMessageViewController *chatController = [[EaseMessageViewController alloc] initWithConversationChatter:@"zlanchun1" conversationType:eConversationTypeChat];//創(chuàng)建基于Demo3.0Class的chatroomChatViewController *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 *)viewControllerdidSelectAvatarMessageModel:(id<IMessageModel>)messageModel {//UserProfileViewController *userprofile = [[UserProfileViewController alloc] initWithUsername:messageModel.nickname];//[self.navigationController pushViewController:userprofile animated:YES]; } - (id<IMessageModel>)messageViewController:(EaseMessageViewController *)viewControllermodelForMessage:(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依賴庫:
- StoreKit.framework
- Bolts.framework
- Parse.framework
- Accounts.framework
- Social.framework。
其中Bolts.framework/Parse.framework在文件夾EaseClass/3rdparty/Parse下。
10
11
刪除重用引用MBProgressHUD庫
12
刪除wav.mm文件。
13
刪除VoiceConvert文件
14
錯誤集合
-
報錯1:未添加Parse依賴庫引起的clang: error: linker command failed with exit code 1 (use -v to see invocation)錯誤。
16
解決辦法:添加parse的依賴庫,一共有5個(環(huán)信小哥告訴我有4個,結(jié)果,添加完4個依賴后,9個錯誤變成4個了。咋辦?還好有Google,查parse依賴關(guān)系,發(fā)現(xiàn)15年7月份依賴增加了一個。)
剩余的4個錯誤("_OBJC_CLASS_$_SKPayment"):
17
看看國外小哥怎么說得(地址)。
18 -
報錯2:刪除重復(fù)引用MBProgressHUD庫
19
-
報錯3:刪除重復(fù)引用wav.mm文件
20 -
報錯4:刪除VoiceConvert文件
21
Demo程序見:這里(百度云盤)
鏈接:http://www.jianshu.com/p/f53be9664f14
總結(jié)
以上是生活随笔為你收集整理的环信集成 2---基于环信Demo3.0,实现单聊功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 阿里沈询:分布式事务原理与实践 | 阿里
- 下一篇: v-on 事件监听器