融云分為IMLib 和IMKit,其中一個(gè)不帶界面的,一個(gè)帶界面的欺劳。首先客戶端把用戶信息傳給我們服務(wù)器獲取融云token这敬,然后根據(jù)融云token 鏈接融云SDK 。
(1) //鏈接融云
-(void)linkFinancialCloud{
if (![[XNUserModel new].rong_token isEqualToString:@""]) {
//融云登錄? token是登錄的時(shí)候獲取的
DLog(@"%@",[XNUserModel new].rong_token);
[[RCDLive sharedRCDLive] connectRongCloudWithToken:[XNUserModel new].rong_token success:^(NSString *loginUserId) {
DLog(@"融云登錄成功loginUserId = %@",loginUserId);
// 設(shè)置當(dāng)前用戶信息,方便發(fā)送消息的時(shí)候攜帶
// 當(dāng)前用戶信息
RCUserInfo *currentUserInfo = [[RCUserInfo alloc]initWithUserId:loginUserId name:[XNUserModel new].nickname portrait:[XNUserModel new].avatar];
// 設(shè)置當(dāng)前用戶信息
[RCDLive sharedRCDLive].currentUserInfo = currentUserInfo;
} error:^(RCConnectErrorCode status) {
DLog(@"融云登錄狀態(tài) %ld", (long)status);
if (status == RC_DISCONN_KICK) {
//[SMGlobalMethod showViewCenter:kKeyWindow.center message:@"登錄"];
}
} tokenIncorrect:^{
}];
}
}
(2)根據(jù)聊天室ID 和 歷史記錄條數(shù) 加入聊天時(shí)?
-(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(), ^{
//發(fā)送直播消息
RCTextMessage *joinChatroomMessage = [[RCTextMessage alloc]init];
joinChatroomMessage.content = [NSString stringWithFormat: @"我們提倡綠色直播媳叨,封面和直播內(nèi)容含吸煙腥光、低俗、引誘糊秆、暴露等都會(huì)被封停賬號(hào)武福。同時(shí)禁止直播聚眾鬧事、集會(huì)痘番,網(wǎng)警24小時(shí)在線巡邏哦"];
//? ? ? ? ? ? ? ? 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:@"錯(cuò)誤代碼:%ld,請(qǐng)嘗試重新登錄",(long)status] cancel:NO completion:^{
[weakSelf baseClose];
[weakSelf.navigationController dismissViewControllerAnimated:YES completion:nil];
}];
});
}];
}
}
(3)發(fā)送消息? // 注意 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 叁执,點(diǎn)贊?