keywordList
,并指定搜索的范围,即是否搜索用户的 userID
、nickName
、remark
字段。V2TIMFriendSearchParam searchParam = new V2TIMFriendSearchParam();searchParam.setKeywordList(keywordList);searchParam.setSearchUserID(true);searchParam.setSearchNickName(true);searchParam.setSearchRemark(true);V2TIMManager.getFriendshipManager().searchFriends(searchParam, new V2TIMValueCallback<List<V2TIMFriendInfoResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendInfoResult> v2TIMFriendInfos) {// 搜索用户资料成功}@Overridepublic void onError(int code, String desc) {// 搜索用户资料失败}});
let param = V2TIMFriendSearchParam()param.keywordList = ["0", "00"]param.isSearchUserID = trueparam.isSearchRemark = trueparam.isSearchNickName = trueV2TIMManager.shared.searchFriends(searchParam: param) { resultList inresultList.forEach { item in// V2TIMFriendInfoResultprint( item.description)}} fail: { code, desc inprint( "searchFriends fail, \\(code), \\(desc)")}
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) {// 搜索用户资料成功} 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_;};V2TIMFriendSearchParam searchParam;searchParam.keywordList = keywordList;searchParam.isSearchUserID = true;searchParam.isSearchNickName = true;searchParam.isSearchRemark = true;auto callback = new ValueCallback<V2TIMFriendInfoResultVector>{};callback->SetCallback([=](const V2TIMFriendInfoResultVector& friendInfoResultList) {// 搜索用户资料成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 搜索用户资料失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->SearchFriends(searchParam, callback);
本页内容是否解决了您的问题?