我们把环信官方的demo项目中的AppKey改成我们自己的:在AppDelegate+EaseMob.m文件中。
然后用test1用户登录,查看发现收到了,test这个用户的 添加好友的申请
1.好友申请处理结果回调
我们这里选择在联系人控制器ContactViewController里监听
//
// ContactViewController.m
#import "ContactViewController.h"
#import "EaseMob.h"
@interface ContactViewController ()<EMChatManagerDelegate>
@end
@implementation ContactViewController
- (void)viewDidLoad {
[super viewDidLoad];
// 标题
self.title = @"联系人";
// 添加(聊天管理器)代理
[[EaseMob sharedInstance].chatManager addDelegate:self delegateQueue:nil];
}
/**
* 移除(聊天管理器)代理
*/
- (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];
}
/*!
@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)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
return 0;
}
/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
// Configure the cell...
return cell;
}
*/
@end
2.演示
注册用户test2,用户test向test2发送好友添加申请,然后test2同意test的好友申请。
观察test用户是否监听到