// 添加关系链监听器V2TIMManager.getFriendshipManager().addFriendListener(listener);// 移除关系链监听器V2TIMManager.getFriendshipManager().removeFriendListener(listener);
// 添加关系链监听器// self 为 id<V2TIMFriendshipListener>[[V2TIMManager sharedInstance] addFriendListener:self];// 移除关系链监听器[[V2TIMManager sharedInstance] removeFriendListener:self];
class FriendshipListener final : public V2TIMFriendshipListener {// 成员 ...};// 添加关系链事件监听器,注意在移除监听器之前需要保持 friendshipListener 的生命期,以免接收不到事件回调FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);// 移除关系链监听器V2TIMManager::GetInstance()->GetFriendshipManager()->RemoveFriendListener(&friendshipListener);
// 获取个人资料String loginUser = V2TIMManager.getInstance().getLoginUser();List<String> userIDList = new ArrayList<>();userIDList.add(loginUser);V2TIMManager.getInstance().getUsersInfo(userIDList, new V2TIMValueCallback<List<V2TIMUserFullInfo>>() {@Overridepublic void onSuccess(List<V2TIMUserFullInfo> profiles) {// 获取个人资料成功}@Overridepublic void onError(int code, String desc) {// 获取个人资料失败}});
// 获取个人资料NSString *loginUser = [[V2TIMManager sharedInstance] getLoginUser];[[V2TIMManager sharedInstance] getUsersInfo:@[loginUser] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {// 获取个人资料成功} fail:^(int code, NSString *desc) {// 获取个人资料失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMString loginUser = V2TIMManager::GetInstance()->GetLoginUser();V2TIMStringVector userIDList;userIDList.PushBack(loginUser);auto callback = new ValueCallback<V2TIMUserFullInfoVector>{};callback->SetCallback([=](const V2TIMUserFullInfoVector& userFullInfoList) {// 获取个人资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取个人资料失败delete callback;});V2TIMManager::GetInstance()->GetUsersInfo(userIDList, callback);
setSelfInfo
(Android / iOS & Mac / Windows) 接口修改个人资料。
个人资料包括昵称、头像、签名、性别、出生日期、好友验证方式等,详情可参考 V2TIMUserFullInfo
(Android / iOS & Mac / Windows) 类定义。
资料修改成功后,您会收到 onSelfInfoUpdated
(Android / iOS & Mac / Windows) 回调。// 设置个人资料V2TIMUserFullInfo info = new V2TIMUserFullInfo();info.setNickname("nickName");info.setFaceUrl("faceUrl");V2TIMManager.getInstance().setSelfInfo(info, new V2TIMCallback() {@Overridepublic void onSuccess() {// 设置个人资料成功}@Overridepublic void onError(int code, String desc) {// 设置个人资料失败}});// 监听个人资料变更回调V2TIMManager.getInstance().addIMSDKListener(new V2TIMSDKListener() {@Overridepublic void onSelfInfoUpdated(V2TIMUserFullInfo info) {// 收到个人资料变更回调}});
// 设置个人资料V2TIMUserFullInfo *info = [[V2TIMUserFullInfo alloc] init];info.nickName = @"nickName";info.faceURL = @"faceURL";[[V2TIMManager sharedInstance] setSelfInfo:info succ:^{// 设置个人资料成功} fail:^(int code, NSString *desc) {// 设置个人资料失败}];// 监听个人资料变更回调[[V2TIMManager sharedInstance] addIMSDKListener:self];- (void)onSelfInfoUpdated:(V2TIMUserFullInfo *)Info {// 收到个人资料变更回调}
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMUserFullInfo info;info.nickName = u8"nickName";info.faceURL = u8"faceUrl";info.modifyFlag = V2TIMUserInfoModifyFlag::V2TIM_USER_INFO_MODIFY_FLAG_NICK |V2TIMUserInfoModifyFlag::V2TIM_USER_INFO_MODIFY_FLAG_FACE_URL;auto callback = new Callback{};callback->SetCallback([=]() {// 设置个人资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 设置个人资料失败delete callback;});V2TIMManager::GetInstance()->SetSelfInfo(info, callback);// 监听个人资料变更回调class SDKListener final : public V2TIMSDKListener {public:SDKListener() = default;~SDKListener() override = default;void OnSelfInfoUpdated(const V2TIMUserFullInfo& info) override {// 收到个人资料变更回调}// 其他成员 ...};// 添加事件监听器,注意在移除监听器之前需要保持 sdkListener 的生命期,以免接收不到事件回调SDKListener sdkListener;V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);
getFriendsInfo
(Android / iOS & Mac / Windows) 接口查询指定的好友资料,调用 setFriendInfo
(Android / iOS & Mac / Windows) 接口修改好友资料。详情请参考 好友管理。List<String> userIDList = new ArrayList<>();userIDList.add("userA");V2TIMManager.getInstance().getUsersInfo(userIDList, new V2TIMValueCallback<List<V2TIMUserFullInfo>>() {@Overridepublic void onSuccess(List<V2TIMUserFullInfo> profiles) {// 获取非好友资料成功}@Overridepublic void onError(int code, String desc) {// 获取非好友资料失败}});
// 获取非好友资料[[V2TIMManager sharedInstance] getUsersInfo:@[@"userA"] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {// 获取非好友资料成功} fail:^(int code, NSString *desc) {// 获取非好友资料失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"userA");auto callback = new ValueCallback<V2TIMUserFullInfoVector>{};callback->SetCallback([=](const V2TIMUserFullInfoVector& userFullInfoList) {// 获取非好友资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取非好友资料失败delete callback;});V2TIMManager::GetInstance()->GetUsersInfo(userIDList, callback);
subscribeUserInfo
(Android / iOS & Mac / Windows) 来订阅非好友用户的资料,订阅成功后,当被订阅的非好友用户资料发生变更时,IM SDK 会通过 onUserInfoChanged
(Android / iOS & Mac / Windows) 回调通知给您。onFriendInfoChanged
或onSelfInfoUpdated
回调来通知给您。List<String> useridList = Arrays.asList("useridA", "useridB", "useridC");V2TIMManager.getInstance().subscribeUserInfo(useridList, new V2TIMCallback() {@Overridepublic void onSuccess() {// 订阅用户资料成功}@Overridepublic void onError(int code, String desc) {// 订阅用户资料失败}});
[V2TIMManager.sharedInstance subscribeUserInfo:@[@"useridA", @"useridB", @"useridC"]succ:^ {// 订阅用户资料成功} fail:^(int code, NSString *desc) {// 订阅用户资料失败}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new Callback{};callback->SetCallback([=]() {// 订阅用户资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 订阅用户资料成功delete callback;});V2TIMManager::GetInstance()->SubscribeUserInfo(userIDList, callback);
List<String> useridList = Arrays.asList("useridA", "useridB", "useridC");V2TIMManager.getInstance().unsubscribeUserInfo(useridList, new V2TIMCallback() {@Overridepublic void onSuccess() {// 取消订阅用户资料成功}@Overridepublic void onError(int code, String desc) {// 取消订阅用户资料失败}});
[V2TIMManager.sharedInstance unsubscribeUserInfo:@[@"useridA", @"useridB", @"useridC"]succ:^ {// 取消订阅用户资料成功} fail:^(int code, NSString *desc) {// 取消订阅用户资料失败}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new Callback{};callback->SetCallback([=]() {// 取消订阅用户资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 取消订阅用户资料失败delete callback;});V2TIMManager::GetInstance()->UnsubscribeUserInfo(userIDList, callback);
onSelfInfoUpdated
和onUserInfoChanged
回调需要您调用addIMSDKListener
(Android / iOS & Mac / Windows) 通过添加 SDK 监听器来设置,onFriendInfoChanged
回调需要您调用 addFriendListener
(Android / iOS & Mac / Windows) 通过添加关系链监听器来设置。onUserInfoChanged
回调进行通知:subscribeUserInfo
订阅成功的用户V2TIMSDKListener v2TIMSDKListener = new V2TIMSDKListener() {@Overridepublic voidonSelfInfoUpdated
(V2TIMUserFullInfo info) {// 收到自己的资料变更通知}@Overridepublic voidonUserInfoChanged
(List<V2TIMUserFullInfo> infoList) {// 收到订阅用户 (非好友) 的资料变更通知}};// 添加 SDK 监听器V2TIMManager.getInstance().addIMSDKListener(v2TIMSDKListener);V2TIMFriendshipListener v2TIMFriendshipListener = new V2TIMFriendshipListener() {@Overridepublic void onFriendInfoChanged(List<V2TIMFriendInfo> infoList) {// 收到好友资料变更通知}};// 添加关系链监听器V2TIMManager.getFriendshipManager().addFriendListener(v2TIMFriendshipListener);
// 添加 SDK 监听器[[V2TIMManager sharedInstance] addIMSDKListener:self];- (void)onSelfInfoUpdated:(V2TIMUserFullInfo *)info {// 收到自己的资料变更回调}- (void)onUserInfoChanged
:(NSArray<V2TIMUserFullInfo *> *)infoList {// 收到订阅用户 (非好友) 的资料变更通知}// 添加关系链监听器[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onFriendProfileChanged:(NSArray<V2TIMFriendInfo *> *)infoList {// 收到好友资料变更通知}
class SDKListener final : public V2TIMSDKListener {public:SDKListener() = default;~SDKListener() override = default;void OnSelfInfoUpdated(const V2TIMUserFullInfo& Info) override {// 收到自己的资料变更回调}void OnUserInfoChanged
(const V2TIMUserFullInfoVector& InfoList) override {// 收到订阅用户 (非好友) 的资料变更通知}// 其他成员函数 ...};// 添加 SDK 事件监听器,注意在移除监听器之前需要保持 sdkListener 的生命期,以免接收不到事件回调SDKListener sdkListener;V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);class FriendshipListener final : public V2TIMFriendshipListener {public:FriendshipListener() = default;~FriendshipListener() override = default;void OnFriendInfoChanged(const V2TIMFriendInfoVector& InfoList) override {// 收到好友资料变更通知}// 其他成员函数 ...};// 添加关系链事件监听器,注意在移除监听器之前需要保持 friendshipListener 的生命期,以免接收不到事件回调FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
本页内容是否解决了您的问题?