registerSDKWithAppKey: 区别app的标识,开发者注册及管理后台
apnsCertName: iOS中推送证书名称。制作与上传推送证书
环信的初始化
[[EaseMob sharedInstance] registerSDKWithAppKey:@"vgios#hxchat" apnsCertName:@””]
环信的初始化 并隐藏日志输出
[[EaseMob sharedInstance] registerSDKWithAppKey:@"vgios#hxchat" apnsCertName:@"" otherConfig:@{kSDKConfigEnableConsoleLogger:@(NO)}];
2.环信登录
同步,block异步
自动登录
[[EaseMob sharedInstance].chatManager setIsAutoLoginEnabled:YES];
[[EaseMob sharedInstance].chatManager asyncRegisterNewAccount:”vgios1” password:”123456” withCompletion:^(NSString *username, NSString *password, EMError *error) {
NSLog(@"error:%@ username:%@ pwd:%@",error,username,password);
} onQueue:nil];
4.自动连接
/*!
@method
@brief 将要发起自动重连操作时发送该回调
@discussion
@result
*/
- (void)willAutoReconnect;
/*!
@method
@brief 自动重连操作完成后的回调(成功的话,error为nil,失败的话,查看error的错误信息)
@discussion
@result
*/
- (void)didAutoReconnectFinishedWithError:(NSError *)error;
环信消息发送的流程
1.先把记录保存到Conversation表
2.接着发送网络请求,API如下
[[EaseMob sharedInstance].chatManager asyncSendMessage:message progress:self prepare:^(EMMessage *message, EMError *error) {
KSLog(@"prepare %@",message.messageBodies);
} onQueue:nil completion:^(EMMessage *message, EMError *error) {
KSLog(@"完成 %@",message.messageBodies);
} onQueue:nil];
7.显示聊天消息
// 1.获取所有历史会话
NSArray *conversations = [[EaseMob sharedInstance].chatManager conversations];
// 2.如果内存中,没有会话,从数据库中加载
if (conversations.count == 0) {
conversations = [[EaseMob sharedInstance].chatManager loadAllConversationsFromDatabaseWithAppend2Chat:YES];
}
10.设置消息为已读
// 设置当前会话所有消息都为已读
[self.conversation markAllMessagesAsRead:YES];
// 设置某条消息为已读
[self.conversation markMessageWithId:<#(NSString *)#> asRead:<#(BOOL)#>]
五、语音
1.准备工作
// 开始录音
[[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:fileName completion:^(NSError *error){
if (error) {
KSLog( @"failure to start recording");
}
}];
// 结束录音
[[EMCDDeviceManager sharedInstance] asyncStopRecordingWithCompletion:^(NSString *recordPath, NSInteger aDuration, NSError *error) {
KSLog(@"%@",recordPath);
}];
3.发送录音
// 语音对象
EMChatVoice *voice = [[EMChatVoice alloc] initWithFile:filePath displayName:@"audio"];
// 消息体
EMVoiceMessageBody *body = [[EMVoiceMessageBody alloc] initWithChatObject:voice];
EMMessage *message = [[EMMessage alloc] initWithReceiver:self.buddy.username bodies:@[body]];
message.messageType = eMessageTypeChat;// 私聊
// 不加密
message.requireEncryption = NO;
4.播放录音
[[EMCDDeviceManager sharedInstance] asyncPlayingWithPath:filePath completion:^(NSError *error) {
NSLog(@"播放完成%@",error);
}];
六、退出(异步方法)
[[EaseMob sharedInstance].chatManager asyncLogoffWithUnbindDeviceToken:YES completion:^(NSDictionary *info, EMError *error) {
if (!error) {//退出成功
}else{//退出失败;
}
} onQueue:nil];
七、是否使用过XMPP,XMPP的实现原理
八、是否使用过环信,简单的说下环信的实现原理