1、建议使用cocoapods导入环信SDK
pod 'HyphenateSDK', :git => 'https://github.com/easemob/hyphenate-cocoapods.git'
2、导入EaseUI,将EaseUI拖入工程中
https://github.com/easemob/easeui_ios/tree/new_dev
最坑的报错如下
原因是因为里面有.c文件,一般情况下出现“Unknown type name”是头文件互相引用出现的,这里可以排除,由于源码使用是c\c++与oc混编,
考虑新的XCode编译文件类型导致的,尝试了几种方案,下面三种可以解决问题。解决方案:.c文件,将属性的 identity and type 改为Objective-C Source。
3、初始化SDK、注册、登录
#pragma mark - setupEMSDK
- (void)setupEMSDK
{
//AppKey:注册的AppKey,详细见下面注释。
//apnsCertName:推送证书名(不需要加后缀),详细见下面注释。
EMOptions *options = [EMOptions optionsWithAppkey:EMSDKAppKey];
options.enableConsoleLog = NO;
options.apnsCertName = EMSDKApnsCertName;
[[EMClient sharedClient] initializeSDKWithOptions:options];
[[EMClient sharedClient] addDelegate:self delegateQueue:nil];
EMError *error1 = [[EMClient sharedClient] registerWithUsername:@"test" password:@"123456"];
if (error1==nil) {
NSLog(@"注册成功");
}else {
MMHLog(@"注册失败");
}
EMError *error = [[EMClient sharedClient] loginWithUsername:@"test" password:@"123456"];
if (!error) {
MMHLog(@"登录成功");
} else {
MMHLog(@"登录失败");
}
}
- (void)applicationWillResignActive:(UIApplication *)application {
}
//APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[EMClient sharedClient] applicationDidEnterBackground:application];
}
// APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[EMClient sharedClient] applicationWillEnterForeground:application];
}
或者后台新建用户
如果有用户登录则变成绿色状态
4、自动登录
EMError *error = [[EMClient sharedClient] loginWithUsername:@"test" password:@"123456"];
if (!error){
[[EMClient sharedClient].options setIsAutoLogin:YES];
}