`·环信官方文档 http://docs.easemob.com/im/300iosclientintegration/10prepareforsdkimport
1.配置证书
2.导入SDK
3.快速集成
3.1 在delegate 配置 Appkey 初初始化 chatManager
#import "AppDelegate.h"
//Lite版本
#import <HyphenateLite/HyphenateLite.h>
@interface AppDelegate ()<EMChatManagerDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//AppKey:注册的AppKey,详细见下面注释。
//apnsCertName:推送证书名(不需要加后缀),详细见下面注释。
EMOptions *options = [EMOptions optionsWithAppkey:@"vgios#xmg1chat"];
options.apnsCertName = nil;
[[EMClient sharedClient] initializeSDKWithOptions:options];
// 写个nil 默认代理会在主线程调用
[[EMClient sharedClient].chatManager addDelegate:self delegateQueue:nil];
return YES;
}
#pragma mark 自动登录的回调
-(void)didAutoLoginWithInfo:(NSDictionary *)loginInfo error:(EMError *)error{
if (!error) {
NSLog(@"%s 自动登录成功 %@",__FUNCTION__, loginInfo);
}else{
NSLog(@"自动登录失败 %@",error);
}
}
// APP进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[[EMClient sharedClient] applicationDidEnterBackground:application];
}
// APP将要从后台返回
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[EMClient sharedClient] applicationWillEnterForeground:application];
}
3.2 注册账号
EMError *error = [[EMClient sharedClient] registerWithUsername:@"zbccc" password:@"zbccc"];
if (error==nil) {
NSLog(@"注册成功");
}
if (error) {
NSLog(@"%@",error.errorDescription);
}
3.2 登录
[[EMClient sharedClient] loginWithUsername:@"zbccc"
password:@"zbccc"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"登录成功");
} else {
NSLog(@"登录失败");
}
}];
//自动登录
EMError *error = [[EMClient sharedClient] loginWithUsername:@"8001" password:@"111111"];
if (!error)
{
[[EMClient sharedClient].options setIsAutoLogin:YES];
}
3.3加好友
[[EMClient sharedClient].contactManager addContact:@"8001"
message:@"我想加您为好友"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"邀请发送成功");
}
}];
//同意好友申请
[[EMClient sharedClient].contactManager approveFriendRequestFromUser:@"8001"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"同意好友成功");
}
}];
//拒绝好友申请
[[EMClient sharedClient].contactManager declineFriendRequestFromUser:@"8001"
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"拒绝好友成功");
}
}];
3.4获取好友
//从服务器获取所有的好友
[[EMClient sharedClient].contactManager getContactsFromServerWithCompletion:^(NSArray *aList, EMError *aError) {
if (!aError) {
NSLog(@"获取成功");
}
}];
//从数据库获取所有的好友
NSArray *userlist = [[EMClient sharedClient].contactManager getContacts];
3.5删除好友
// 删除好友
[[EMClient sharedClient].contactManager deleteContact:@"8001"
isDeleteConversation: YES
completion:^(NSString *aUsername, EMError *aError) {
if (!aError) {
NSLog(@"删除成功");
}
}];
APNs 离线推送
http://docs.easemob.com/im/300iosclientintegration/75apns