假定你已經(jīng)集成了靜態(tài)庫,動(dòng)態(tài)庫,設(shè)置了bitcode,AppID綁定了推送,push Notifation 已經(jīng)打開,接下來就是要實(shí)現(xiàn)聊天,視頻,推送等等。
環(huán)信的demo一上來猛一看,很懵逼,沒辦法,一點(diǎn)點(diǎn)摳,把你需要的模塊都摳出來,包括資源,圖片,等等,[這里我只集成單聊,群組]。

目錄.png
1、把不用的全部刪掉,(我主要把紅包,聊天室,機(jī)器人相關(guān)的全部刪除)。
還有記得 call 文件夾下的全部刪除,廢棄

廢棄.png
2、pch 文件,已經(jīng)國際化的配置,包括頭文件的配置(我這里使用的全部的sdk 所以,DEMO_CALL 為 1)

pch.png
3、最重要就是MainViewController的替換以及ChatDemoHelper的替換。
demo 里,根控制器是帶NavBar 的TarbbarController,而TarbarController 又包含了三個(gè)子控制器。
針對(duì)項(xiàng)目結(jié)構(gòu)自己做調(diào)整,頭文件不用變,替換你需要的類
#import <UIKit/UIKit.h>
#import <UserNotifications/UserNotifications.h>
@interface LXTabbarController : UITabBarController
{
EMConnectionState _connectionState;
}
- (void)jumpToChatList;
- (void)setupUntreatedApplyCount;
- (void)setupUnreadMessageCount;
- (void)networkChanged:(EMConnectionState)connectionState;
- (void)didReceiveLocalNotification:(UILocalNotification *)notification;
- (void)didReceiveUserNotification:(UNNotification *)notification;
- (void)playSoundAndVibration;
- (void)showNotificationWithMessage:(EMMessage *)message;
@end
.m 里 關(guān)于接口的方法可以直接拿demo的方法使用,只是在配置子控制的地方自己設(shè)置。

配置.png
#pragma mark - 添加所有的子控制器
- (void)addAllChildViewControllers {
//
//
_chatListVC= [[ConversationListController alloc] init];
[_chatListVC networkChanged:_connectionState];
[self addOneChildViewController:_chatListVC image:[UIImage imageNamed:@"tabbar_chats"] selectedImage:[UIImage imageNamed:@"tabbar_chatsHL"] title:@"會(huì)話"];
//
_contactsVC = [[ContactListViewController alloc] init];
[self addOneChildViewController:_contactsVC image:[UIImage imageNamed:@"tabbar_contacts"]
selectedImage:[UIImage imageNamed:@"tabbar_contactsHL"] title:@"通訊錄"];
//
FourViewController *businessVc = [[FourViewController alloc] init];
[self addOneChildViewController:businessVc image:[UIImage imageNamed:@"tabbar_setting"] selectedImage:[UIImage imageNamed:@"tabbar_settingHL@2x"] title:@"設(shè)置"];
}
#pragma mark - 添加一個(gè)子控制器
- (void)addOneChildViewController:(UIViewController *)viewController image:(UIImage *)image selectedImage:(UIImage *)selectedImage title:(NSString *)title {
UINavigationController *navC = [[UINavigationController alloc] initWithRootViewController:viewController];
navC.navigationBar.barTintColor = [UIColor colorWithRed:0.47 green:0.83 blue:0.98 alpha:1];
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
attributes[NSForegroundColorAttributeName] = [UIColor colorWithWhite:0.996 alpha:1.000];
navC.navigationBar.titleTextAttributes = attributes;
navC.tabBarItem.title = title;
navC.tabBarItem.image = image;
navC.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
navC.tabBarItem.selectedImage = selectedImage;
[self addChildViewController:navC];
}
如果你也是和我一樣,使用Tabbar 配置Navbar的結(jié)構(gòu),有個(gè)地方需要注意:

角標(biāo).png
4、最重要的是把ChatDemoHelper里修改一下

Help接口.png
替換所有的MainViewController,設(shè)置MainController
#import "ChatDemoHelper.h"
#import "AppDelegate.h"
#import "ApplyViewController.h"
#import "MBProgressHUD.h"
#import "EaseSDKHelper.h"
#if DEMO_CALL == 1
#import "DemoCallManager.h"
#endif
static ChatDemoHelper *helper = nil;
@implementation ChatDemoHelper
+ (instancetype)shareHelper
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
helper = [[ChatDemoHelper alloc] init];
});
return helper;
}
- (void)dealloc
{
[[EMClient sharedClient] removeDelegate:self];
[[EMClient sharedClient].groupManager removeDelegate:self];
[[EMClient sharedClient].contactManager removeDelegate:self];
[[EMClient sharedClient].roomManager removeDelegate:self];
[[EMClient sharedClient].chatManager removeDelegate:self];
}
- (id)init
{
self = [super init];
if (self) {
[self initHelper];
}
return self;
}
#pragma mark - setter
- (void)setMainVC:(LXTabbarController *)mainVC
{
_mainVC = mainVC;
#if DEMO_CALL == 1
[[DemoCallManager sharedManager] setMainController:mainVC];
#endif
}
#pragma mark - init
- (void)initHelper
{
[[EMClient sharedClient] addDelegate:self delegateQueue:nil];
[[EMClient sharedClient].groupManager addDelegate:self delegateQueue:nil];
[[EMClient sharedClient].contactManager addDelegate:self delegateQueue:nil];
[[EMClient sharedClient].roomManager addDelegate:self delegateQueue:nil];
[[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
#if DEMO_CALL == 1
[DemoCallManager sharedManager];
#endif
}
剩下的 和Demo中直接復(fù)制過來。
最后說一下環(huán)信的推送:
環(huán)信的推送應(yīng)用在后臺(tái)是不會(huì)推送的,需要在接收消息的地方,判斷當(dāng)前應(yīng)用的活躍狀態(tài),然后做本地推送。
- (void)didReceiveMessages:(NSArray *)aMessages
{
BOOL isRefreshCons = YES;
for(EMMessage *message in aMessages){
BOOL needShowNotification = (message.chatType != EMChatTypeChat) ? [self _needShowNotification:message.conversationId] : YES;
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];
}
}
}
好了,基本功能都實(shí)現(xiàn)了。