要实现的效果:

方法:

#pragma mark - tableViewDelegate
/***  实现这个方法,滑动表格cell就会出现Delete按钮*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{if (editingStyle == UITableViewCellEditingStyleDelete ) {// 获取要删除的好友的名字EMBuddy *buddy = self.buddyList[indexPath.row];NSString *username = buddy.username;// 删除好友//removeFromRemote:是否将自己从对方好友列表中移除[[EaseMob sharedInstance].chatManager removeBuddy:username removeFromRemote:YES error:nil];}
}

最后联系人控制器代码如下:

//
//  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];
}/*!@method@brief 接收到好友请求时的通知@discussion@param username 发起好友请求的用户username@param message  收到好友请求时的say hello消息*/
- (void)didReceiveBuddyRequest:(NSString *)username message:(NSString *)message
{// 弹出提示,让用户选择“同意”还是“拒绝”UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"好友添加请求" message:message preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"同意" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {// 同意加好友申请[[EaseMob sharedInstance].chatManager acceptBuddyRequest:username error:nil];}]];[alert addAction:[UIAlertAction actionWithTitle:@"拒绝" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {// 拒绝加好友申请[[EaseMob sharedInstance].chatManager rejectBuddyRequest:username reason:@"我不认识你" error:nil];}]];[self presentViewController:alert animated:YES completion:nil];
}/***  当其他用户向你发出“加好友”请求,你同意后会调用这个方法*  当你“删除好友”之后也会调用这个方法*/
- (void)didUpdateBuddyList:(NSArray *)buddyList changedBuddies:(NSArray *)changedBuddies isAdd:(BOOL)isAdd
{// 重新赋值数据源self.buddyList = buddyList;// 刷新表格[self.tableView reloadData];
}/***  好友删除了你会调用这个方法*/
- (void)didRemovedByBuddy:(NSString *)username
{// 当好友删除了你,一般我们不会提示,但会刷新你联系人数据// 把新的好友显示到表格[[EaseMob sharedInstance].chatManager asyncFetchBuddyListWithCompletion:^(NSArray *buddyList, EMError *error) {if (!error) {// 赋值数据源self.buddyList = buddyList;// 刷新表格[self.tableView reloadData];}} onQueue: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;
}#pragma mark - tableViewDelegate
/***  实现这个方法,滑动表格cell就会出现Delete按钮*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{if (editingStyle == UITableViewCellEditingStyleDelete ) {// 获取要删除的好友的名字EMBuddy *buddy = self.buddyList[indexPath.row];NSString *username = buddy.username;UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"删除好友" message:@"确定要删除该好友?" preferredStyle:UIAlertControllerStyleAlert];[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {// 删除好友//removeFromRemote:是否将自己从对方好友列表中移除[[EaseMob sharedInstance].chatManager removeBuddy:username removeFromRemote:YES error:nil];}]];[self presentViewController:alert animated:YES completion:nil];}
}@end

03环信好友管理 - 删除好友相关推荐

  1. 03环信好友管理 - 获取好友列表

    获取好友列表,环信提供了4种方法. 从本地获取:该方法比较特殊,只有在您之前获取过好友列表的情况下才会有值,且不能保证最新. NSArray *buddyList = [[EaseMob shared ...

  2. 03环信好友管理 - 添加好友(好友申请)

    EMChatManagerBuddyDelegate Ø上面的协议的实现了对用户的基本操作,如 (1)添加好友 (2)从本地获取好友列表 (3)从服务器获取最新好友列表 (4)接收好友添加请求 (5) ...

  3. 【2021环信IM快速集成指南】PC Web、Uni-App、小程序集成都在这里了

    本文将直白且详细的描述一下如何集成环信web端的IM SDK,(小程序.Uni-app通用).这是一篇快速集成攻略,其中更多的是对于官网文档的一篇注释说明,相信很多的小伙伴在准备将环信的IM即时通讯能 ...

  4. 环信即时通讯云iOS版V2.0.9.1服务评测

    集成测试 评测环境 2G/3G/WiFi网络下: 测评环境 MAC OS(10.9.2)+ XCode(5.1) + iPhone 测试对象 环信即时通讯云 IOS SDK Version 2.0.9 ...

  5. 环信的使用以及注意事项!

    参考文档: http://docs.easemob.com/im/200androidclientintegration/10androidsdkimport   环信官网. Demo 下载 : ht ...

  6. 基于环信实现在线聊天功能

    由于最近接触到的项目需要用到聊天功能,关于聊天的SDK跟安卓同事统一,最终选择了环信.在官方下载好SDK,并研究了一波,最终实现自定义聊天功能. ###实现前准备 1.下载环信SDK,我使用的版本是V ...

  7. 环信java_java环信服务端注册IM代码

    https://github.com/easemob/emchat-server-examples 里面包含各种语言版本,我只下载了java版emchat-server-java 把代码放到自己的项目 ...

  8. 即时通信---环信SDK(IOS)使用教程

    一. 提前准备 注册环信即时通讯云账号 下载iOS的环信SDK 登陆到管理后台 在我的应用中创建一个应用 在苹果的个人开发中心创建一个推送证书(当然不创建也没用关系,只是不能推送消息而已) 创建完证书 ...

  9. Android环信爬坑指北(二)头像昵称好友备注显示

      在上一篇文章中提到了要在初始化的时候,设置用户信息提供者类--EaseUserProfileProvider,用以获取用户信息.下面我们来看一下 EaseUserProfileProvider 是 ...

  10. 七(6)环信-用户体系集成-联系人管理

    课程总结 1.即时通信 环信通信 执行过程 2.用户体系集成 用户注册时分配环信账号 客户端获取环信账号,自动登录环信服务器 3.联系人业务处理 好友申请 查看联系人列表 一. 即时通信-环信介绍 1 ...

最新文章

  1. 数据库索引-基本知识
  2. 149. Max Points on a Line同一条线上的最多点数
  3. python使用for循环打印99乘法表-python3:使用for循环打印九九乘法表
  4. Day7 - 面向对象编程进阶及其他相关
  5. 2021-01-22 使用 Docker 打包 Python 项目
  6. 常用javascript代码
  7. x86架构linux内核引导过程分析,SylixOS---x86引导过程分析
  8. autocomplete=off inpu属性
  9. python如何确定拐点_多年股市老鸟买卖操作经验——如何在波段操作确定买入点!经典...
  10. 【土地评价与土地管理】案例:某地区土地农业利用潜力评价
  11. Flink 源码 | 自定义 Format 消费 Maxwell CDC 数据
  12. JavaScript 框架库 - jQuery
  13. cad---菜单,工具栏,屏幕菜单,增强工具栏
  14. 世界域名后缀大全,所有国家域名后缀都有
  15. 【BZOJ1492】【NOI2007】货币兑换 Cash(CDQ分治,斜率优化)
  16. 工程师文化:BAT为什么不喊老板?
  17. 2022年江西省建筑三类人员(企业主要负责人A证)练习题及答案
  18. PlatformIO使用Arduino[Ticker]库(ESP8266)
  19. 网易我的世界服务器如何安组件,网易我的世界组件包怎么使用
  20. 多WAN口宽带路由器到底几个口才算合理(转)

热门文章

  1. 趣谈网络协议学习笔记[计算机网络]
  2. 使用一键重装工具制作U盘启动盘失败的解决方法
  3. 计算机无法识别Gp80180,GP80160,GP80180网口修改IP设置教程
  4. java如何获取管理员权限
  5. Java面试回忆录:java电子书免费
  6. 操作系统概念第九版编程项目:Linux内核模块
  7. 快解析:管家婆C9异地访问解决方案
  8. fifaol3服务器位置,FIFAOL3新手教学 讲解球场上的每个位置
  9. 中国地图和地方特点介绍
  10. NMEA-0183协议(多星联合定位)