I have rarely written a project summary recently. Although I have done a lot of projects recently, they are all outsourcing projects, and there is nothing worth summarizing after doing it. A recent project used Rongyun Instant Communication. In the past, I used to use environmental communication, so I encountered some problems. I will summarize and record them here.
1 User information such as avatar and nickname (Rongyun has two ways to deal with this problem)
1. User information provider
Implementation steps (the following code is placed in a singleton, which can be AppDelegate, it is best to write a singleton separately)
First, comply with the RCIMUserInfoDataSource protocol
Then set up a proxy
[[RCIM sharedRCIM] setUserInfoDataSource:self];
Finally implement the proxy method:
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *))completion { NSLog(@"getUserInfoWithUserId ----- %@", userId); RCUserInfo *user = [RCUserInfo new]; if (userId == nil || [userId length] == 0) { = userId; = @""; = @""; completion(user); return; } if ([userId isEqualToString:[UserInfo shareInstance].uid]) { NSString *urlSelf = [BASIC_URL_image stringByAppendingString:[UserInfo shareInstance].photo]; return completion([[RCUserInfo alloc] initWithUserId:userId name:[UserInfo shareInstance].nickname portrait:urlSelf]); }else { //According to the model of storing contact information, use userId to obtain the corresponding name and avatar url, and make the following settings [WTBaseHttpRequst postRequstWithURL:getUserHttp params:@{@"uid":[UserInfo shareInstance].uid, @"api_token":[UserInfo shareInstance].api_token, @"k_uid":userId} successBlock:^(NSDictionary *returnData) { if ([returnData[@"status"] integerValue] == 1) { NSString *urlStr = [BASIC_URL_image stringByAppendingString:returnData[@"data"][@"user"][@"photo"]]; return completion([[RCUserInfo alloc] initWithUserId:userId name:returnData[@"data"][@"user"][@"nickname"] portrait:urlStr]); }else { completion(user); } } failureBlock:^(NSString *error) { completion(user); } showHUD:NO]; } }
This method does not require you to call it manually, it is just called when you modify the user information
[[RCIM sharedRCIM] refreshUserInfoCache:user withUserId:[UserInfo shareInstance].uid]
Just do it
WS(weakSelf); //Call to modify user information[WTBaseHttpRequst postRequstWithURL:modifyInfoHttp params:dict successBlock:^(NSDictionary *returnData) { [weakSelf MBProgressHudShowWithTextOnlyWithText:returnData[@"msg"]]; if ([returnData[@"status"] integerValue] == 1) { RCUserInfo *user = [RCUserInfo new]; = [UserInfo shareInstance].uid; = [BASIC_URL_image stringByAppendingString:[UserInfo shareInstance].photo]; = ; [[RCIM sharedRCIM] refreshUserInfoCache:user withUserId:[UserInfo shareInstance].uid]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [ popViewControllerAnimated:YES]; }); } } failureBlock:^(NSString *error) { [weakSelf MBProgressHudShowWithTextOnlyWithText:error]; } showHUD:YES];
2. Carry user information in extended messages
Set the user information to carry in the message body when sending a message (after adding user information after 2.4.1, the cell will display the avatar of the attached user information by default, that is, the user information will not retrieve the user information provided by the user information provider)
[RCIM sharedRCIM].enableMessageAttachUserInfo = YES;
After you set enableMessageAttachUserInfo, you can get it
/** * Sender information * **/ @property(nonatomic, strong) RCUserInfo *senderUserInfo;
Of course, I think we can also get the friend relationship from the background. After each login, we open a thread to request the friend relationship and save it and then search for the friend's nickname and avatar according to the ring signal ID.
2 Add a prompt to the input box (I always think that the ring letter should have been modified by the method, but I haven't found this method, so I have to write it myself)
1. Create a label for prompts
_lab = [[UILabel alloc] initWithFrame:]; _lab.text = @"Please enter text information..."; _lab.textColor = [UIColor colorWithHexColor:@"dddddd"]; _lab.font = [UIFont systemFontOfSize:15]; _lab.center = CGPointMake(_lab. + 15, _lab.);
2. Determine whether there is a draft to show and hide the label of the prompt
[ addSubview:_lab]; if ( == nil || == 0) { _lab.hidden = NO; }else { _lab.hidden = YES; }
3. Determine the display hidden prompt label based on the input data
- (void)inputTextView:(UITextView *)inputTextView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { if ((( == 1 && [text isEqualToString:@""]) || ( == 0 && > 0)) && == 1 && == 0) { _lab.hidden = NO; }else { _lab.hidden = YES; } }
3 Cancel input @ pop-up friend list interface, keep the method of long pressing the avatar @
1. First enable the message@ function in AppDelegate (only support group chats and discussion groups, the App needs to implement group member data source groupMemberDataSource)
[RCIM sharedRCIM].enableMessageMentioned = YES;
Then call it in the controller inheriting the RCConversationViewController
-(void)showChooseUserViewController:(void (^)(RCUserInfo *selectedUserInfo))selectedBlock cancel:(void (^)())cancelBlock { }
4 Add some fixed cell to the session list (inheriting RCConversationListViewController)
// Assign values to custom cell- (RCConversationBaseCell *)rcConversationListTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RCCustomCell *cell = (RCCustomCell *)[[RCCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"RCCustomCell"]; RCConversationModel *model = []; = ; return cell; } // Add a custom cell's data source- (NSMutableArray *)willReloadTableData:(NSMutableArray *)dataSource{ NSArray *arr = @[@"Forum Reply and @My", @"Support from strangers", @"Survivor Tribe @My", @"Questions"]; for (int i = 0; i<; i++) { RCConversationModel *model = [[RCConversationModel alloc]init]; = RC_CONVERSATION_MODEL_TYPE_CUSTOMIZATION; = arr[i]; = YES; [dataSource insertObject:model atIndex:i]; } return dataSource; } // Click on cell to jump- (void)onSelectedTableRow:(RCConversationModelType)conversationModelType conversationModel:(RCConversationModel *)model atIndexPath:(NSIndexPath *)indexPath{ if ( == 0) { WTForumAndConnectListViewController *chatList = (WTForumAndConnectListViewController *)[WTStoryBoardSegment instantiateViewControllerWithStoryBoardName:@"Main" identifier:@"WTForumAndConnectListViewController"]; = @"Reply and @My"; [ pushViewController:chatList animated:YES]; }else if ( == 1) { WTChatListViewController *chatList = [[WTChatListViewController alloc] init]; = @"Support from strangers"; = YES; = 1; = ; [ pushViewController:chatList animated:YES]; }else if ( == 2) { WTChatListViewController *chatList = [[WTChatListViewController alloc] init]; = @"Survivor Tribe @My"; = YES; = 2; [ pushViewController:chatList animated:YES]; }else if ( == 3) { WTQuestionnaireViewController *questionnaire = (WTQuestionnaireViewController *)[WTStoryBoardSegment instantiateViewControllerWithStoryBoardName:@"Main" identifier:@"WTQuestionnaireViewController"]; [ pushViewController:questionnaire animated:YES]; }else { //Click the cell to get the corresponding model of the cell, then get the corresponding RCUserInfo from the model, then assign the session attributes to enter the session if ( == ConversationType_PRIVATE) {//Single chat WTMyConversationLisViewController *_conversationVC = [[WTMyConversationLisViewController alloc]init]; _conversationVC.conversationType = ; _conversationVC.targetId = ; _conversationVC.title = ; [ pushViewController:_conversationVC animated:YES]; }else if ( == ConversationType_GROUP){//Group chat WTMyConversationLisViewController *_conversationVC = [[WTMyConversationLisViewController alloc]init]; _conversationVC.conversationType = ; _conversationVC.title = ; _conversationVC.targetId = ; [ pushViewController:_conversationVC animated:YES]; } } }
5 Get the number of chat lists and delete lists anywhere
Get a chat list
NSArray *privateArr = [[RCIMClient sharedRCIMClient] getConversationList:@[@(ConversationType_PRIVATE)]];
Adding the corresponding type of chat in ConversationList can get the corresponding type of chat list and delete the method like
[[RCIMClient sharedRCIMClient] clearConversations:@[@(ConversationType_PRIVATE)]];
6 Background image
The default image of Rongyun chat list without data is clicked on the upper right corner to join the chat, but not all chats have this function (mine does not have it). How to find it in the resource file without it? Use ps to remove the following line of words😆
7 Others
The above are some of the problems and solutions I encountered during the use of the fusion cloud. If there are any errors or shortcomings, I hope to correct them. Thank you! I also hope everyone supports me.