Browse SDKs · iOS
Platform
SDKsiOS

Search friends

Search the current user’s friends with OpenIM iOS SDK.

Copy

Search local friend records matching specified keywords using searchFriends:onSuccess:onFailure:.

Parameters

ParameterTypeRequiredDescription
paramOIMSearchFriendsParam *YesSearch parameter object specifying keywords and matching scopes. If keywords are empty, clear search UI results immediately.

Search parameter attributes (OIMSearchFriendsParam)

ParameterTypeRequiredDescription
keywordListNSArray<NSString *> *YesList of search keyword strings.
isSearchUserIDBOOLNoWhether to match keywords against user IDs.
isSearchNicknameBOOLNoWhether to match keywords against friend nicknames.
isSearchRemarkBOOLNoWhether to match keywords against friend remarks.

Code example

OIMSearchFriendsParam *param = [OIMSearchFriendsParam new];
param.keywordList = @[keyword];
param.isSearchUserID = YES;
param.isSearchNickname = YES;
param.isSearchRemark = YES;

[[OIMManager manager] searchFriends:param
                           onSuccess:^(NSArray<OIMSearchFriendsInfo *> *items) {
                               [searchStore replaceResults:items];
                           }
                           onFailure:^(NSInteger code, NSString *message) {
                               NSLog(@"searchFriends failed: %ld %@", (long)code, message);
                           }];

Return value

The onSuccess callback delivers an array of OIMSearchFriendsInfo matching the search criteria.

State changes after the call

  • Local state merge: Search results form an isolated, ephemeral result set; do not overwrite the primary contact directory cache.
  • Snapshot query: Friend searches capture a local database snapshot and do not emit friendship delegate events.