好友管理
本文档旨在指导开发者如何使用融云即时通讯 iOS IMLib SDK 实现添加好友、删除好友、查看好友列表、管理好友等功能。
提示
好友管理功能在 5.12.0 版本开始支持。
开通服务
信息托管服务已默认开通,您可以直接使用好友管理功能。
好友事件监听
为了及时接收好友添加删除、好友申请状态、好友全部清理、好友信息变更多端回调变更通知,你需要在应用调用 IMLib SDK 的初始化之后,且在调用 IMLib SDK 的连接之前,设置订阅好友事件监听器的代理委托,并实现 RCFriendEventDelegate 协议的相关代理方法。
您可以调用 addFriendEventDelegate 设置好友事件监听器。如果不想再接收好友事件,可调用 removeFriendEventDelegate 接口移除设置的监听。
提示
信息托管服务中,好友操作产生的 SDK 通知回调也是一种状态通知行为,所以不管应用中是否实现好友事件的监听,服务端都会对客户端 SDK 进行状态同步,确保本地好友关系的状态是最新的,这些通知会计入消息的分发、下行数据统计中。
示例代码
Objective C
// 添加好友事件监听
[[RCCoreClient sharedCoreClient] addFriendEventDelegate:self];
// 移除好友事件监听
[[RCCoreClient sharedCoreClient] removeFriendEventDelegate:self];
// -------- 回调事件 ----------
// 好友添加回调
- (void)onFriendAdd:(NSString *)userId
name:(NSString *)name
portraitUri:(NSString *)portraitUri
directionType:(RCDirectionType)directionType
operationTime:(long long)operationTime {
}
// 好友删除回调
- (void)onFriendDelete:(NSArray<NSString *> *)userIds
directionType:(RCDirectionType)directionType
operationTime:(long long)operationTime {
}
// 好友申请状态回调事件
- (void)onFriendApplicationStatusChanged:(NSString *)userId
applicationType:(RCFriendApplicationType)applicationType
applicationStatus:(RCFriendApplicationStatus)status
directionType:(RCDirectionType)directionType
operationTime:(long long)operationTime
extra:(NSString *)extra {
}
// 好友全部清理回调事件。注意:此操作只能由服务端发起
- (void)onFriendCleared:(long long)operationTime {
}
// 好友信息变更多端回调事件
- (void)onFriendInfoChangedSync:(NSString *)userId
remark:(NSString *)remark
extProfile:(NSDictionary<NSString *,NSString *> *)extProfile
operationTime:(long long)operationTime {
}