removeFriendListener
(Android / iOS and Mac / Windows) to remove the relationship event listener.// Add a relationship listenerV2TIMManager.getFriendshipManager().addFriendListener(listener);// Remove the relationship listenerV2TIMManager.getFriendshipManager().removeFriendListener(listener);
// Add a relationship listener// `self` is id<V2TIMFriendshipListener>.[[V2TIMManager sharedInstance] addFriendListener:self];// Remove the relationship listener[[V2TIMManager sharedInstance] removeFriendListener:self];
class FriendshipListener final : public V2TIMFriendshipListener {// Member...};// Add a relationship event listener. Keep `friendshipListener` valid before the listener is removed to ensure event callbacks are received.FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);// Remove the relationship listenerV2TIMManager::GetInstance()->GetFriendshipManager()->RemoveFriendListener(&friendshipListener);
getUsersInfo
API (Android / iOS and Mac / Windows) and enter a user's UserID
for the userIDList
parameter to query the user's profile.// Obtain a user's personal profileString 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) {// User's profile obtained successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain the user's profile}});
// Obtain a user's personal profileNSString *loginUser = [[V2TIMManager sharedInstance] getLoginUser];[[V2TIMManager sharedInstance] getUsersInfo:@[loginUser] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {// User's profile obtained successfully} fail:^(int code, NSString *desc) {// Failed to obtain the user's profile}];
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) {// User's profile obtained successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtain the user's profiledelete callback;});V2TIMManager::GetInstance()->GetUsersInfo(userIDList, callback);
setSelfInfo
API (Android / iOS and Mac / Windows) to modify a user's profile.
A user's profile includes the user's nickname, profile photo, status, gender, birth date, and friend request approval method. For more information, see the definitions of the V2TIMUserFullInfo
class (Android / iOS and macOS / Windows).
After the profile is modified successfully, you will receive the onSelfInfoUpdated
callback (Android / iOS and Mac / Windows).// Set the user's profileV2TIMUserFullInfo info = new V2TIMUserFullInfo();info.setNickname("nickName");info.setFaceUrl("faceUrl");V2TIMManager.getInstance().setSelfInfo(info, new V2TIMCallback() {@Overridepublic void onSuccess() {// User's profile set successfully}@Overridepublic void onError(int code, String desc) {// Failed to set the user's profile}});// Listen for the callback for a user's profile changeV2TIMManager.getInstance().addIMSDKListener(new V2TIMSDKListener() {@Overridepublic void onSelfInfoUpdated(V2TIMUserFullInfo info) {// Received the callback for a user's profile change}});
// Set the user's profileV2TIMUserFullInfo *info = [[V2TIMUserFullInfo alloc] init];info.nickName = @"nickName";info.faceURL = @"faceURL";[[V2TIMManager sharedInstance] setSelfInfo:info succ:^{// User's profile set successfully} fail:^(int code, NSString *desc) {// Failed to set the user's profile}];// Listen for the callback for a user's profile change[[V2TIMManager sharedInstance] addIMSDKListener:self];- (void)onSelfInfoUpdated:(V2TIMUserFullInfo *)Info {// Received the callback for a user's profile change}
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([=]() {// User's profile set successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to set the user's profiledelete callback;});V2TIMManager::GetInstance()->SetSelfInfo(info, callback);// Listen for the callback for a user's profile changeclass SDKListener final : public V2TIMSDKListener {public:SDKListener() = default;~SDKListener() override = default;void OnSelfInfoUpdated(const V2TIMUserFullInfo& info) override {// Received the callback for a user's profile change}// Other members …};// Add an event listener. Keep `sdkListener` valid before the listener is removed to ensure event callbacks are received.SDKListener sdkListener;V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);
getFriendsInfo
API (Android / iOS and macOS / Windows) to query the profile of the specified friend. And you can call setFriendInfo
API (Android / iOS and Mac / Windows) to modify the profile of the specified friend. For more information, see Friend Management.getUsersInfo
API (Android / iOS and Mac / Windows) and enter the UserID
of a non-friend user for the userIDList
parameter to query the profile of the non-friend user.List<String> userIDList = new ArrayList<>();userIDList.add("userA");V2TIMManager.getInstance().getUsersInfo(userIDList, new V2TIMValueCallback<List<V2TIMUserFullInfo>>() {@Overridepublic void onSuccess(List<V2TIMUserFullInfo> profiles) {// Obtained the profile of the non-friend user successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain the profile of the non-friend user}});
// Get the profile of a non-friend user[[V2TIMManager sharedInstance] getUsersInfo:@[@"userA"] succ:^(NSArray<V2TIMUserFullInfo *> *infoList) {// Obtained the profile of the non-friend user successfully} fail:^(int code, NSString *desc) {// Failed to obtain the profile of the non-friend user}];
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) {// Obtained the profile of the non-friend user successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtain the profile of the non-friend userdelete callback;});V2TIMManager::GetInstance()->GetUsersInfo(userIDList, callback);
subscribeUserInfo
API (Android / iOS and Mac / Windows) to subscribe to the profiles of non-friend users. Once successfully subscribed, the SDK will notify you of any changes to the subscribed user's profile via the onUserInfoChanged
(Android / iOS and Mac / Windows) callback.onFriendInfoChanged
or onSelfInfoUpdated
callback.List<String> useridList = Arrays.asList("useridA", "useridB", "useridC");V2TIMManager.getInstance().subscribeUserInfo(useridList, new V2TIMCallback() {@Overridepublic void onSuccess() {// Subscription to user profile successful.}@Overridepublic void onError(int code, String desc) {// Subscription to user profile failed.}});
[V2TIMManager.sharedInstance subscribeUserInfo:@[@"useridA", @"useridB", @"useridC"]succ:^ {// Subscription to user profile successful.} fail:^(int code, NSString *desc) {// Subscription to user profile failed.}];
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([=]() {// Subscription to user profile successful.delete callback;},[=](int error_code, const V2TIMString& error_message) {// Subscription to user profile failed.delete callback;});V2TIMManager::GetInstance()->SubscribeUserInfo(userIDList, callback);
unsubscribeUserInfo
API (Android / iOS and Mac / Windows) to cancel the subscription for certain users. List<String> useridList = Arrays.asList("useridA", "useridB", "useridC");V2TIMManager.getInstance().unsubscribeUserInfo(useridList, new V2TIMCallback() {@Overridepublic void onSuccess() {// Unsubscription to user profile successful.}@Overridepublic void onError(int code, String desc) {// Unsubscription to user profile failed.}});
[V2TIMManager.sharedInstance unsubscribeUserInfo:@[@"useridA", @"useridB", @"useridC"]succ:^ {// Unsubscription to user profile successful.} fail:^(int code, NSString *desc) {// Unsubscription to user profile failed.}];
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([=]() {// Unsubscription to user profile successful.delete callback;},[=](int error_code, const V2TIMString& error_message) {// Unsubscription to user profile failed.delete callback;});V2TIMManager::GetInstance()->UnsubscribeUserInfo(userIDList, callback);
onSelfInfoUpdated
(Android / iOS and Mac / Windows) callback.onFriendInfoChanged
(Android / iOS and Mac / Windows) callback.onUserInfoChanged
(Android / iOS and Mac / Windows) callback.addIMSDKListener
(Android / iOS and Mac / Windows) to add an SDK listener. For the onFriendInfoChanged callback, call addFriendListener
(Android / iOS and Mac / Windows) to add a relationship listener.onUserInfoChanged
callback if the users meet the following conditions:subscribeUserInfo
.V2TIMSDKListener v2TIMSDKListener = new V2TIMSDKListener() {@Overridepublic voidonSelfInfoUpdated
(V2TIMUserFullInfo info) {// Receive notification of changes to your own profile}@Overridepublic voidonUserInfoChanged
(List<V2TIMUserFullInfo> infoList) {// Receive notification of changes to subscribed user (non-friend) profiles}};// Add an SDK listenerV2TIMManager.getInstance().addIMSDKListener(v2TIMSDKListener);V2TIMFriendshipListener v2TIMFriendshipListener = new V2TIMFriendshipListener() {@Overridepublic void onFriendInfoChanged(List<V2TIMFriendInfo> infoList) {// Receive notification of changes to friend profiles}};// Add a relationship listenerV2TIMManager.getFriendshipManager().addFriendListener(v2TIMFriendshipListener);
// Add an SDK listener[[V2TIMManager sharedInstance] addIMSDKListener:self];- (void)onSelfInfoUpdated:(V2TIMUserFullInfo *)info {// Receive notification of changes to your own profile}- (void)onUserInfoChanged
:(NSArray<V2TIMUserFullInfo *> *)infoList {// Receive notification of changes to subscribed user (non-friend) profiles}// Add a relationship listener[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onFriendProfileChanged:(NSArray<V2TIMFriendInfo *> *)infoList {// Receive notification of changes to friend profiles}
class SDKListener final : public V2TIMSDKListener {public:SDKListener() = default;~SDKListener() override = default;void OnSelfInfoUpdated(const V2TIMUserFullInfo& Info) override {// Receive notification of changes to your own profile}void OnUserInfoChanged
(const V2TIMUserFullInfoVector& InfoList) override {// Receive notification of changes to subscribed user (non-friend) profiles}// Other members ...};// Add an SDK event listener. Keep `sdkListener` valid before the listener is removed to ensure event callbacks are received.SDKListener sdkListener;V2TIMManager::GetInstance()->AddSDKListener(&sdkListener);class FriendshipListener final : public V2TIMFriendshipListener {public:FriendshipListener() = default;~FriendshipListener() override = default;void OnFriendInfoChanged(const V2TIMFriendInfoVector& InfoList) override {// Receive notification of changes to friend profiles}// Other members ...};// Add a relationship event listener. Keep `friendshipListener` valid before the listener is removed to ensure event callbacks are received.SDKListener sdkListener;FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
Was this page helpful?