Browse SDKs · iOS
Platform
SDKsiOS

Retrieve public profiles by user ID

Batch-retrieve public application-user profiles as OIMPublicUserInfo objects by userID.

Copy

Batch-query public application user profiles by userID using getUsersInfo:onSuccess:onFailure:. This method is designed for displaying stranger profile cards and presenting candidate profiles in friend addition workflows. When searching by nickname, mobile number, organization, or email address, have your application backend return candidate user IDs first, then retrieve their public profiles using this API.

Parameters

ParameterTypeRequiredDescription
userIDsNSArray<NSString *> *YesList of user IDs to query. Deduplicate entries and constrain batch request sizes in production.

Code example

NSArray<NSString *> *inputUserIDs = @[@"user_a", @"user_b", @"user_a"];
NSArray<NSString *> *userIDs = [NSOrderedSet orderedSetWithArray:inputUserIDs].array;

[[OIMManager manager] getUsersInfo:userIDs
                         onSuccess:^(NSArray<OIMPublicUserInfo *> *users) {
                             for (OIMPublicUserInfo *user in users) {
                                 publicUsersByID[user.userID] = user;
                             }
                         }
                         onFailure:^(NSInteger code, NSString *message) {
                             NSLog(@"getUsersInfo failed: %ld %@", (long)code, message);
                         }];

Return value

The onSuccess callback delivers an array of OIMPublicUserInfo objects corresponding to the queried IDs:

PropertyTypeDescription
userIDNSString *The unique OpenIM user identifier.
nicknameNSString *Account-level public nickname.
faceURLNSString *Account-level public avatar URL.
exNSString *Account-level custom extension field formatted according to business specifications.

The ex field is read-only in this context. Client devices cannot directly mutate other users' public profiles. To update the current authenticated user's profile and extension properties, refer to Update your profile.

Cache management and data refreshing

This method returns an instantaneous snapshot of public user metadata at the time of invocation and does not trigger real-time profile change events. Re-fetch profiles by userID when displaying user detail views, pulling to refresh, reconnecting after network drops, or upon receiving push notifications from your application backend. When rendering lists containing multiple users, collect visible IDs, deduplicate them, execute batch queries, and merge results by userID.

The SDK does not emit generic profile-change delegates for arbitrary remote users. The onSelfInfoUpdated: callback exclusively delivers profile updates for the currently logged-in account and must not be written into public user caches for other accounts.

Search and add friends

When searching for new contacts, retrieve candidate IDs from your backend service before looking up their OpenIM public profiles:

[userDirectory searchUserIDs:keyword completion:^(NSArray<NSString *> *candidateIDs) {
    if (candidateIDs.count == 0) {
        [searchStore replaceResults:@[]];
        return;
    }

    [[OIMManager manager] getUsersInfo:candidateIDs
                             onSuccess:^(NSArray<OIMPublicUserInfo *> *users) {
                                 [searchStore replaceResults:users];
                             }
                             onFailure:^(NSInteger code, NSString *message) {
                                 NSLog(@"getUsersInfo failed: %ld %@", (long)code, message);
                             }];
}];

When your system supports exact user ID search, pass the input directly as userID. For fuzzy search, prefix matching, or searching by custom business attributes, obtain candidate IDs from your backend directory service.

Select models by scenario

ScenarioPreferred model
Application user search, stranger profile cardsOIMPublicUserInfo
Friend lists, address books, friend remarksOIMFriendInfo
Group member rosters, in-group aliases, member role levelsOIMGroupMemberInfo

The same userID can have different display titles and relationship data across contexts. Never overwrite a custom friend remark or group member nickname with an account's public nickname.

Next steps