iOS 環(huán)信3.2.3 集成聊天,語音,視頻,通話

假定你已經(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)了。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,030評(píng)論 25 709
  • 最近項(xiàng)目中有涉及到即時(shí)通訊的功能,所用到的是環(huán)信3.1.5的sdk。下面就開始介紹其過程: (1)集成環(huán)信SDK:...
    帶你去旅行閱讀 4,115評(píng)論 7 15
  • Familiar functions are also shipped with the solution, fo...
    老翅閱讀 240評(píng)論 0 1
  • 信是當(dāng)今時(shí)代最大的缺失,是因?yàn)槎?亂 人類社會(huì)的發(fā)展,是人格文化、知識(shí)信息豐富、科技進(jìn)步、生活質(zhì)量提升的過程。那么...
    懶爺邱閱讀 258評(píng)論 1 2
  • 班級(jí)情況: 教學(xué)目標(biāo): 校區(qū):科學(xué)創(chuàng)想樂高機(jī)器人和平校區(qū) 時(shí)間:周六10:30——11:30 學(xué)員:劉梓希 任教老...
    bong撒卡啦卡閱讀 275評(píng)論 0 0

友情鏈接更多精彩內(nèi)容