Browse SDKs · iOS
Platform
SDKsiOS

Retrieve the friend list by page

Retrieve the current iOS user’s friend list with pagination.

Copy

Retrieve the authenticated user's friend list with pagination using getFriendListPageWithOffset:count:filterBlack:onSuccess:onFailure:. Paginating friend queries prevents memory spikes and UI hitches in large contact directories.

Parameters

ParameterTypeRequiredDescription
offsetNSIntegerYesPagination starting offset index. Pass 0 for the initial page.
countNSIntegerYesNumber of friend items to fetch per page.
filterBlackBOOLYesWhether to filter out users currently present on the user's blacklist. Pass YES to omit blacklisted friends.

Code example

[[OIMManager manager] getFriendListPageWithOffset:0
                                             count:50
                                       filterBlack:YES
                                         onSuccess:^(NSArray<OIMFriendInfo *> *friends) {
                                             [friendStore replaceFirstPage:friends];
                                         }
                                         onFailure:^(NSInteger code, NSString *message) {
                                             NSLog(@"getFriendListPage failed: %ld %@", (long)code, message);
                                         }];

When fetching subsequent pages, increment offset by the count of items already loaded and deduplicate contact records by userID.

Return value

The onSuccess callback returns an NSArray<OIMFriendInfo *> * containing friend items for the requested page. When the returned array is empty or contains fewer than count items, all friends have been retrieved.

State changes after the call

  • Snapshot creation: The paginated query creates an initial data snapshot and does not emit friendship delegate callbacks.
  • Asynchronous event listening: Register OIMFriendshipListener to merge incremental friend additions, remark updates, and friend removals in real time.
@interface FriendshipStore () <OIMFriendshipListener>
@end

@implementation FriendshipStore

- (void)startListening {
    [[OIMManager callbacker] addFriendListener:self];
}

- (void)stopListening {
    [[OIMManager callbacker] removeFriendListener:self];
}

- (void)onFriendAdded:(OIMFriendInfo *)info {
    [friendStore mergeFriend:info];
}

- (void)onFriendInfoChanged:(OIMFriendInfo *)info {
    [friendStore mergeFriend:info];
}

- (void)onFriendDeleted:(OIMFriendInfo *)info {
    [friendStore removeUserID:info.userID];
}

@end

Retain this listener instance strongly, and invoke removeFriendListener: when signing out or releasing the contacts view model.