Skip to main content

Add Friends

The Add Friends page allows you to query user information. Enter a user's Application ID in the search field and tap Search. The IMKit SDK will then fetch the user's details from the server. IMKit provides RCUserSearchViewController, a search page class based on UIKit's UITableView.

The Add Friends page typically consists of three components: a navigation bar, search bar, and friend list.

Initialization

Initialize the Add Friends page by calling the RCUserSearchViewController class constructor. Note that you need to create an RCUserSearchViewModel object as the business logic handler for RCUserSearchViewController.

Parameters

ParameterTypeDescription
viewModelRCUserSearchViewModelThe business logic handler for RCUserSearchViewController. Manages UI configuration and user information retrieval.

Sample Code

RCUserSearchViewModel *viewModel = [[RCUserSearchViewModel alloc] init];
RCUserSearchViewController *vc = [[RCUserSearchViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];

Customization

The IMKit SDK allows customization of the Add Friends interface.

Custom Title Bar

IMKit's RCUserSearchViewController uses the system navigation bar to display the page title. Subclass RCUserSearchViewController and set the title via the title property in the viewDidLoad method.

Sample Code

- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"New Title";
}

RCUserSearchViewController supports custom search bars. Set the delegate property of RCUserSearchViewModel and implement the corresponding delegate methods to customize search functionality.

Sample Code

RCUserSearchViewModel *viewModel = [[RCUserSearchViewModel alloc] init];
viewModel.delegate = self;
RCUserSearchViewController *vc = [[RCUserSearchViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];

...

/// Configure custom search functionality
- (RCSearchUserProfileViewModel *_Nullable)willConfigureSearchBarViewModelForUserSearchViewModel:(RCUserSearchViewModel *)viewModel {
// Return your custom search ViewModel
}

...

Custom User Profile Display

RCUserSearchViewController supports custom logic for displaying user profiles. Set the delegate property of RCUserSearchViewModel and implement the corresponding delegate methods.

Sample Code

RCUserSearchViewModel *viewModel = [[RCUserSearchViewModel alloc] init];
viewModel.delegate = self;
RCUserSearchViewController *vc = [[RCUserSearchViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];

...

/// Configure custom user profile display. Returns: Whether the app handles the action [YES: SDK won't process; NO: SDK handles internally]
- (BOOL)userSearchViewModel:(RCUserSearchViewModel *)viewModel showUserProfile:(RCUserProfile *)profile {
}

...

Custom Search Events

RCUserSearchViewController supports custom search events. Set the delegate property of RCUserSearchViewModel and implement the corresponding delegate methods.

Sample Code

RCUserSearchViewModel *viewModel = [[RCUserSearchViewModel alloc] init];
viewModel.delegate = self;
RCUserSearchViewController *vc = [[RCUserSearchViewController alloc] initWithViewModel:viewModel];
[self.navigationController pushViewController:vc animated:YES];

...

/// Trigger custom search events. Returns: Whether the app handles the action [YES: SDK won't process; NO: SDK handles internally]
- (BOOL)userSearchViewModel:(RCUserSearchViewModel *)viewModel searchUserProfileWithText:(NSString *)text {
}

...