步骤如下:
1、下载SDKhttp://www.easemob.com/download
证书下载上传
后期发送消息 需要推送发送的内容
http://docs.easemob.com/doku.php?id=im:300iosclientintegration:10prepareforsdkimport
2、导入下载好的SDK
2.导入下载好的SDK.png3、添加依赖库
CoreMedia.framework
AudioToolbox.framework
AVFoundation.framework
MobileCoreServices.framework
ImageIO.framework
SystemConfiguration.framework
libc++.dylib
libresolv.dylib
libz.dylib
libstdc++.6.0.9.dylib
libsqlite3.dylib
添加-force_load
target -> build settings -> 搜索other linker flags -> 双击other linker flags后边添加-force_load -> 将libHyphenateSDK.a拖到-force_load下边(出现10个警告)如果拖libHyphenateFullSDK.a文件 会出现4个错误
注意:SDK不支持bitcode,向Build Settings → Linking(搜bit) → Enable Bitcode中设置NO。
3.添加依赖库.png
4、运行编译器,检查是否报错
4.运行编译器,检查是否报错.png5、真机错误修复
5.真机错误修复.jpg6.5、导入libiconv
6.5导入libiconv.jpg6、导入EaseUI框架
6.导入EaseUI框架.jpg7、导入静态库 运行后会有很多报错
7.导入静态库 运行后会有很多报错.png8、添加PCH到工程
8.添加PCH到工程.png9、将PCH文件修改成相对路径
9.将PCH文件修改成相对路径.png10、注册环信
10.注册环信.png11、实现单聊功能
11.实现单聊功能.png注册环信
1)导入头文件#import "EMSDK.h"
(2)注册代码
EMOptions *options = [EMOptions optionsWithAppkey:@"xuanyi#im"];
options.apnsCertName = @"DDD";
[[EMClient sharedClient] initializeSDKWithOptions:options];
(3)用户注册
EMError *error = [[EMClient sharedClient] registerWithUsername:@"ming" password:@"111"];
(4)用户登录
EMError *error = [[EMClient sharedClient] loginWithUsername:@"ming" password:@"111"];
(5)添加好友
《1》EMError *error = [[EMClient sharedClient].contactManager addContact:@"xiao" message:@"..."];
《2》[[EMClient sharedClient].contactManager addDelegate:self delegateQueue:nil];
《3》成功didReceiveAgreedFromUsername:
《4》遭拒绝didReceiveDeclinedFromUsername:
注意:
如果项目中使用-ObjC有冲突,可以添加-force_load来解决, 添加-force_load:
targets->build setting->other linker flags->添加-force_load->静态库拖动到他的下面,-force_load[空格]EaseMobSDK/lib/libHyphenateSDK.a(静态库的路径)。
代码:
-
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//AppKey:注册的appKey,详细见下面注释。
//apnsCertName:推送证书名(不需要加后缀),详细见下面注释。
EMOptions *options = [EMOptions optionsWithAppkey:@"chen0828#childrenstory"];
options.apnsCertName = @"not";
[[EMClient sharedClient] initializeSDKWithOptions:options];[[EaseSDKHelper shareHelper] easemobApplication:application
didFinishLaunchingWithOptions:launchOptions
appkey:@"chen0828#childrenstory"
apnsCertName:@"not"
otherConfig:@{kSDKConfigEnableConsoleLogger:[NSNumber numberWithBool:YES]}];
return YES;
}
// App进入后台 -
(void)applicationDidEnterBackground:(UIApplication *)application
{
[[EMClient sharedClient] applicationDidEnterBackground:application];
}
// App将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[EMClient sharedClient] applicationWillEnterForeground:application];
}
网友评论