03环信好友管理 - 好友请求同意后刷新联系人列表
来源:互联网 发布:手机淘宝4.2.2安卓版 编辑:程序博客网 时间:2024/06/11 14:18
需求:当用户test向用户test3申请添加好友,test3同意后,用户test的联系人列表应该刷新(最初没有test3这个好友)
实现:所以我们应该在“好友请求”被接受时的回调方法里,向服务器请求最新的好友数据
我们这里需要在ContactViewController控制器的 - didAcceptedByBuddy:方法中添加一些代码,最终该方法代码如下:
#pragma mark - EMChatManagerDelegate/*! @method @brief 好友请求被接受时的回调 @discussion @param username 之前发出的好友请求被用户username接受了 */- (void)didAcceptedByBuddy:(NSString *)username{ NSString *message = [NSString stringWithFormat:@"%@ 同意了你的好友请求",username]; // 提示 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"好友添加消息" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:alert animated:YES completion:nil]; // 把新的好友显示到表格 [[EaseMob sharedInstance].chatManager asyncFetchBuddyListWithCompletion:^(NSArray *buddyList, EMError *error) { if (!error) { // 赋值数据源 self.buddyList = buddyList; // 刷新表格 [self.tableView reloadData]; } } onQueue:nil];}最后ContactViewController.m 代码如下:
//// ContactViewController.m#import "ContactViewController.h"#import "EaseMob.h"@interface ContactViewController ()<EMChatManagerDelegate>/** * 好友列表数据源 */@property(nonatomic,strong)NSArray *buddyList;@end@implementation ContactViewController- (void)viewDidLoad { [super viewDidLoad]; // 标题 self.title = @"联系人"; // 添加(聊天管理器)代理 [[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil]; // 获取好友列表数据 self.buddyList = [[EaseMob sharedInstance].chatManager buddyList];}/** * 移除(聊天管理器)代理 */- (void)dealloc{ [[EaseMob sharedInstance].chatManager removeDelegate:self];}#pragma mark - EMChatManagerDelegate/*! @method @brief 好友请求被接受时的回调 @discussion @param username 之前发出的好友请求被用户username接受了 */- (void)didAcceptedByBuddy:(NSString *)username{ NSString *message = [NSString stringWithFormat:@"%@ 同意了你的好友请求",username]; // 提示 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"好友添加消息" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:alert animated:YES completion:nil]; // 把新的好友显示到表格 [[EaseMob sharedInstance].chatManager asyncFetchBuddyListWithCompletion:^(NSArray *buddyList, EMError *error) { if (!error) { // 赋值数据源 self.buddyList = buddyList; // 刷新表格 [self.tableView reloadData]; } } onQueue:nil];}/*! @method @brief 好友请求被拒绝时的回调 @discussion @param username 之前发出的好友请求被用户username拒绝了 */- (void)didRejectedByBuddy:(NSString *)username{ NSString *message = [NSString stringWithFormat:@"%@ 拒绝了你的好友请求",username]; // 提示 UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"好友添加消息" message:message preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:nil]]; [self presentViewController:alert animated:YES completion:nil];}#pragma mark - Table view data source- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return self.buddyList.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *ID = @"buddyCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID forIndexPath:indexPath]; // 1.获取"好友"模型 EMBuddy *buddy = self.buddyList[indexPath.row]; // 2.配置cell数据 cell.imageView.image = [UIImage imageNamed:@"chatListCellHead"]; cell.textLabel.text = buddy.username; return cell;}@end效果演示:
0 0
- 03环信好友管理 - 好友请求同意后刷新联系人列表
- 03环信好友管理 - 获取好友列表
- 03环信好友管理 - 监听"加好友"的请求
- 03环信好友管理 - 删除好友
- 03环信好友管理 - 添加好友(好友申请)
- 03环信好友管理 - 添加好友(好友申请处理结果回调)
- 实现微信好友列表
- 环信添加好友
- PC端 Spark 二次开发 自动接收好友请求并同意
- 好友列表
- 好友列表
- 好友列表
- 好友列表
- 微信 通讯录 好友列表显示
- iOS 好友请求列表数据库处理
- xmpp 好友列表,删除好友
- python 获取微信好友列表(微信web)
- 好友
- 1020. 月饼 (25)
- Volley学习记录(四)
- [从头学数学] 第84节 长方体和正方体
- Poj1325 Machine Schedule
- 学习C# 继承 封装 多态
- 03环信好友管理 - 好友请求同意后刷新联系人列表
- hdu 5500 Reorder the Books【贪心】【思维】
- 数据结构循环队列
- 【BZOJ1556】墓地秘密 DP
- 给UITableView添加UITapGestureRecognizer 每个Item多事件点击出现崩溃
- 通讯录的联系人操作(CRUD)
- UVa--514 Rails (stack)
- 《Linux常用命令第一关(1)》
- 【报表神器】——ECharts