关于融云直播间即时通讯集成的小总结

融云分为IMLib 和IMKit,其中一个不带界面的,一个带界面的。首先客户端把用户信息传给我们服务器获取融云token,然后根据融云token 链接融云SDK 。
(1) //链接融云

-(void)linkFinancialCloud{
if (![[XNUserModel new].rong_token isEqualToString:@""]) {
//融云登录token是登录的时候获取的
DLog(@"%@",[XNUserModel new].rong_token);
[[RCDLive sharedRCDLive] connectRongCloudWithToken:[XNUserModel new].rong_token success:^(NSString *loginUserId) {
DLog(@"融云登录成功loginUserId = %@",loginUserId);
【关于融云直播间即时通讯集成的小总结】// 设置当前用户信息,方便发送消息的时候携带
// 当前用户信息
RCUserInfo *currentUserInfo = [[RCUserInfo alloc]initWithUserId:loginUserId name:[XNUserModel new].nickname portrait:[XNUserModel new].avatar];
// 设置当前用户信息
[RCDLive sharedRCDLive].currentUserInfo = currentUserInfo;
} error:^(RCConnectErrorCode status) {
DLog(@"融云登录状态 %ld", (long)status);
if (status == RC_DISCONN_KICK) {
//[SMGlobalMethod showViewCenter:kKeyWindow.center message:@"登录"];
}
} tokenIncorrect:^{
}];
}
}
(2)根据聊天室ID 和 历史记录条数 加入聊天时
-(void)joinChatRoom{

WS(weakSelf);
if (self.conversationType == ConversationType_CHATROOM) {
[[RCIMClient sharedRCIMClient]joinChatRoom:self.preModel.anchor_uid messageCount:self.defaultHistoryMessageCountOfChatRoom success:^{
dispatch_async(dispatch_get_main_queue(), ^{
//发送直播消息
RCTextMessage *joinChatroomMessage = [[RCTextMessage alloc]init];
joinChatroomMessage.content = [NSString stringWithFormat: @"我们提倡绿色直播,封面和直播内容含吸烟、低俗、引诱、暴露等都会被封停账号。同时禁止直播聚众闹事、集会,网警24小时在线巡逻哦"];
//joinChatroomMessage.extra = @"0";
joinChatroomMessage.extra = [YDExtraModel extraJsonWithType:0 userLevel:nil fansLevel:nil fansName:nil medal:nil];
joinChatroomMessage.senderUserInfo.name = @"直播消息:";
[weakSelf sendMessage:joinChatroomMessage pushContent:@""];
});
} error:^(RCErrorCode status) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showAlertWithMessage:[NSString stringWithFormat:@"错误代码:%ld,请尝试重新登录",(long)status] cancel:NO completion:^{
[weakSelf baseClose];
[weakSelf.navigationController dismissViewControllerAnimated:YES completion:nil];
}];
});
}];
}
}
(3)发送消息// 注意 self.conversationType 为聊天
[[RCDLive sharedRCDLive] sendMessage:self.conversationType

targetId:self.preModel.anchor_uid
content:messageContent
pushContent:pushContent
pushData:nil
success:^(long messageId) {
} error:^(RCErrorCode nErrorCode, long messageId) {
[[RCIMClient sharedRCIMClient]deleteMessages:@[ @(messageId) ]];
}];
messageContent 中填入普通的消息和礼物消息RCDLiveGiftMessage

礼物消息类型 1 礼物,0 ,点赞

    推荐阅读