iOS环信3.1·集成·功能的实现

  • SDK集成

1.准备工作:

·此处假设你已经申请过环信的开发者账号。
·此处假设你已经在Apple开发者中心配置好证书,并上传至环信。
·如果你不需要离线消息的推送功能,可以不必配置证书。
·从环信官网下载好的最新SDK,解压缩到一易找的地方。

2.将ios_IM_sdk_V3.1.5文件夹中的HyphenateFullSDK文件夹拷贝到你的工程目录文件夹下。

img_f14fb57401407c0bbbf6a26b5b070703.png
Paste_Image.png

3.打开Xcode,按下快捷键:Alt+Command+A,将 HyphenateFullSDK添加到工程目录里。
img_d89679b6759c39c66073ed9eb3883047.png
Paste_Image.png

4.将 HyphenateFullSDK目录下的 include中的 EMSDK.h中的代码注释掉一部分:
img_fe20524208ed8bff2b404ee35ac8752a.png
Paste_Image.png

5.将 HyphenateFullSDK目录下的 include中的 EMSDKFull.h中的代码注释掉一部分:
img_b76fa486166a4b6a58e882dc0dc29b7e.png
Paste_Image.png

6.点 Build PhasesLink Binary With Libraries,添加依赖库

SDK 包含实时语音依赖库有:
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework
MobileCoreServices.framework
ImageIO.framework
libc++.dylib
libz.dylib
libstdc++.6.0.9.dylib
libsqlite3.dylib
libiconv.dylib
**(如果使用的是 xcode7,后缀为 tbd。)**

img_e282b3d16093b9f87356fb680b5c5543.png
Paste_Image.png

7.将 ios_IM_sdk_V3.1.5文件夹中的 EaseUI文件夹 拷贝到你的 工程目录文件夹下。
img_936c74397d6608ab4e7cf1a15019d0d4.png
Paste_Image.png

8.打开Xcode,按下快捷键:Alt+Command+A,将 EaseUI添加到工程目录里。
img_423c2e544d586de82d89939ae42243d5.png
Paste_Image.png

9.在你的 XXX.pch头文件的首尾部分,加入两行代码:
img_963b2a82070e6b2367048bf030cea406.png
Paste_Image.png

//另,注意:必须引入这两个系统库。否则会报错。
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

错误是这样:

img_7a31d7fffbecec0620e069ee8b49bd76.png
Paste_Image.png

10.可能存在的 Error· 需要解决

环信中有MJRefresh,若你的工程中也引入了MJRefresh,请自行删除你的或者环信EaseUI中的MJRefresh任一即可。
当然,前提是,保证你的MJRefresh是最新的
环信中有SDWebImage库,所以,如果你有用到SDWebImage库,请自行删除你引入的SDWebImage。
当然,你可以选择不删除。但是,要做一点简单的操作。
只需在XXX.pch中删除之前的引用#import "UIImage+WebCache",换成引用#import "UIImage+EMWebCache"

11.集成的结尾,说明部分:

经过上面一系列的修改以及添加库。此时,需要测试一下。
按下快捷键:Command+B,编译应该会无误通过。

  • 功能实现
包含:位置发送、语音发送、图片发送、拍照发送、语音通讯、视频通讯

1.引入环信官方Demo中的:ChatViewController.hChatViewController.m
注释掉ChatViewController.m如下代码部分,解决Error
简单来讲,就是注释掉红色警告行的代码即可。

//#import "ChatGroupDetailViewController.h"
//#import "ChatroomDetailViewController.h"
//#import "UserProfileViewController.h"
//#import "UserProfileManager.h"
//#import "ContactListSelectViewController.h"
//#import "ChatDemoHelper.h"
//#import "EMChooseViewController.h"
//#import "ContactSelectionViewController.h"
//if (ext && ext[kHaveUnreadAtMessage] != nil)
//  {
//   NSMutableDictionary *newExt = [ext mutableCopy];
//   [newExt removeObjectForKey:kHaveUnreadAtMessage];
//   self.conversation.ext = newExt;
//   }
//UserProfileViewController *userprofile = [[UserProfileViewController alloc] initWithUsername:messageModel.message.from];
//[self.navigationController pushViewController:userprofile animated:YES];
//ContactSelectionViewController *selectController = [[ContactSelectionViewController alloc] initWithContacts:members];
//selectController.mulChoice = NO;
//selectController.delegate = self;
//[self.navigationController pushViewController:selectController animated:YES];
//ContactSelectionViewController *selectController = [[ContactSelectionViewController alloc] initWithContacts:members];
//selectController.mulChoice = NO;
//selectController.delegate = self;
//[self.navigationController pushViewController:selectController animated:YES];
//UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:model.nickname];
//if (profileEntity) {
//    model.avatarURLPath = profileEntity.imageUrl;
//    model.nickname = profileEntity.nickname;
//}
//    [[ChatDemoHelper shareHelper] setChatVC:nil];
//        ChatGroupDetailViewController *detailController = [[ChatGroupDetailViewController alloc] initWithGroupId:self.conversation.conversationId];
//        [self.navigationController pushViewController:detailController animated:YES];
//        ChatroomDetailViewController *detailController = [[ChatroomDetailViewController alloc] initWithChatroomId:self.conversation.conversationId];
//        [self.navigationController pushViewController:detailController animated:YES];
//        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];
//- (BOOL)viewController:(EMChooseViewController *)viewController didFinishSelectedSources:(NSArray *)selectedSources
//{
//    if ([selectedSources count]) {
//        EaseAtTarget *target = [[EaseAtTarget alloc] init];
//        target.userId = selectedSources.firstObject;
//        UserProfileEntity *profileEntity = [[UserProfileManager sharedInstance] getUserProfileByUsername:target.userId];
//        if (profileEntity) {
//            target.nickname = profileEntity.nickname == nil ? profileEntity.username : profileEntity.nickname;
//        }
//        if (_selectedCallback) {
//            _selectedCallback(target);
//        }
//    }
//    else {
//        if (_selectedCallback) {
//            _selectedCallback(nil);
//        }
//    }
//    return YES;
//}
//- (void)viewControllerDidSelectBack:(EMChooseViewController *)viewController
//{
//    if (_selectedCallback) {
//        _selectedCallback(nil);
//    }
//}

2.引入环信官方Demo中的:
ChatDemoHelper.hChatDemoHelper.mCallViewController.hCallViewController.m
删除ChatDemoHelper.m中的
介于

-(void) initHelper {
#ifdef REDPACKET_AVALABLE
    [[RedPacketUserConfig sharedConfig] beginObserveMessage];
#endif
    [[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
    [[EMClient sharedClient].callManager addDelegate:self delegateQueue:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(makeCall:) name:KNOTIFICATION_CALL object:nil];
#endif
}

#pragma mark - EMCallManagerDelegate

之间的所有代码。

当然,还是会有报错。

下面的代码也要删除:

-(void)_clearHelper {
    self.mainVC = nil;
    self.conversationListVC = nil;
    self.chatVC = nil;
    self.contactViewVC = nil;
    [[EMClient sharedClient] logout:NO];
#if DEMO_CALL == 1
    [self hangupCallWithReason:EMCallEndReasonFailed];
#endif
}

当然,你这样点击音视频按钮,还是不能弹出通话界面。
所以,你需要在你的XXX.pch头文件里加入这么一行代码即可。

#define DEMO_CALL 1

img_01af92a732b0865decdfe5b8405d6f51.png
Paste_Image.png

要若想能弹出通话界面,设置根控制器,必须是这样的。
也就是在ChatDemoHelper.h中必须将你的聊天界面的控制器声明,命名最好是 mainVC。这样会比较省事儿。
img_4b2ebb974e20f5c850f955b74a2d770b.png
Paste_Image.png

在AppDelegate.m,加入这样的一句代码:

//tabBarCtr为你的聊天界面的视图控制器。可以是Tabbar,或者别的。
[ChatDemoHelper shareHelper].mainVC = tabBarCtr;
CECNavigationViewController *callNav = nil;  
CECChatRootController *tabBarCtr = [[CECChatRootController alloc] init];
[ChatDemoHelper shareHelper].mainVC = tabBarCtr;
callNav = [[CECNavigationViewController alloc] initWithRootViewController:tabBarCtr]; 
callNav.navigationBarHidden = YES;
self.window.rootViewController = callNav;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值