tencent cloud

Feedback

Android&iOS&Windows&Mac

Last updated: 2024-07-08 15:38:17

    Overview

    Only locally stored users can be searched for, such as contacts or user profiles that have been pulled.
    Note:
    The local user search feature is supported only by Enhanced SDK v5.4.666 or later.
    The local user profile search feature is only available on the IM Premium edition. To use it, purchase the Premium Edition.

    Searching for the Local User Profile

    Call the searchFriends API (Android / iOS and Mac / Windows) to search for the local user profile. You can set the search keyword keywordList and specify the search scope to set whether to search by the userID, nickName, and remark fields of a user.
    Sample code:
    Android
    iOS and macOS
    Windows
    V2TIMFriendSearchParam searchParam = new V2TIMFriendSearchParam();
    searchParam.setKeywordList(keywordList);
    searchParam.setSearchUserID(true);
    searchParam.setSearchNickName(true);
    searchParam.setSearchRemark(true);
    
    V2TIMManager.getFriendshipManager().searchFriends(searchParam, new V2TIMValueCallback<List<V2TIMFriendInfoResult>>() {
    @Override
    public void onSuccess(List<V2TIMFriendInfoResult> v2TIMFriendInfos) {
    // User profile found successfully
    }
    
    @Override
    public void onError(int code, String desc) {
    // Failed to find the user profile
    }
    });
    V2TIMFriendSearchParam *searchParam = [[V2TIMFriendSearchParam alloc] init];
    searchParam.keywordList = @[@"keyword1", @"keyword2"];
    searchParam.isSearchUserID = YES;
    searchParam.isSearchNickName = YES;
    searchParam.isSearchRemark = YES;
    [[V2TIMManager sharedInstance] searchFriends:searchParam succ:^(NSArray<V2TIMFriendInfoResult *> *resultList) {
    // User profile found successfully
    } fail:^(int code, NSString *desc) {
    // Failed to find the user 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_;
    };
    
    V2TIMFriendSearchParam searchParam;
    searchParam.keywordList = keywordList;
    searchParam.isSearchUserID = true;
    searchParam.isSearchNickName = true;
    searchParam.isSearchRemark = true;
    
    auto callback = new ValueCallback<V2TIMFriendInfoResultVector>{};
    callback->SetCallback(
    [=](const V2TIMFriendInfoResultVector& friendInfoResultList) {
    // User profile found successfully
    delete callback;
    },
    [=](int error_code, const V2TIMString& error_message) {
    // Failed to find the user profile
    delete callback;
    });
    
    V2TIMManager::GetInstance()->GetFriendshipManager()->SearchFriends(searchParam, callback);
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support