Skip to main content

tip

When you enable User Profile Hosting, the chat UI and conversation list in IMKit SDK will retrieve user profiles from the hosting service, rendering the following features obsolete.

User Profile

This document describes how to configure nicknames, avatars, and other profile details for users, groups, and group members. Key topics include:

  • Setting nicknames and avatars for the currently logged-in user.
  • Implementing multiple provider protocols to supply user, group, member, and member list data from the application layer to IMKit SDK for display purposes.
  • Methods for persistently storing user profiles, group info, and member details.

Enable Persistent Storage

IMKit SDK supports persisting user profiles, group info, and member details in a local database. Note: Member list data cannot be persistently stored.

To enable local persistence, set the enablePersistentUserInfoCache property of the RCIM class to YES. Data will then be cached in both memory and the database, remaining available after app restarts.

tip
  • Configure persistence properties after initializing the SDK but before establishing a connection.
  • By default, enablePersistentUserInfoCache is NO, meaning data is only cached in memory and cleared when the app terminates. The SDK will re-fetch this data via provider protocols upon next launch.

Sample Code

[RCIM sharedRCIM].enablePersistentUserInfoCache = YES;

Understanding Provider Protocols

IMKit SDK provides the following provider protocols for retrieving user profile data from the application layer. Developers must implement these protocols to supply accurate data.

The application layer only needs to provide data sources. IMKit SDK automatically requests these protocols when displaying profile information, then handles avatar/nickname updates and UI refreshes.

tip
  • Set profile providers after initializing the SDK but before connecting.
  • We recommend implementing these protocols in AppDelegate or other singleton instances.

During runtime, IMKit SDK follows this workflow for profile data:

  1. When displaying user/group info, the SDK first checks memory caches.
  2. If cached or locally stored data exists, it's returned directly to the UI layer without triggering provider callbacks.
  3. If no cached data exists, the SDK invokes the appropriate provider protocol to request data from the application layer, then refreshes the UI.

Set Current User Profile

After establishing a connection with RC servers, set the current user's profile to ensure proper avatar display in the SDK interface.

If the provided userId doesn't match the logged-in user, IMKit SDK will ignore the data.

Sample Code

RCUserInfo *_currentUserInfo = [[RCUserInfo alloc] initWithUserId:userId name:userNickName portrait:userPortraitUri];

[RCIM sharedRCIM].currentUserInfo = _currentUserInfo;
tip

Configure this after successfully connecting to RC servers, typically within the connection success callback.

Configure Other User Profiles

Implement the User Profile Provider (RCIMUserInfoDataSource protocol) to supply profile data (nickname, avatar, etc.) for non-local users.

Delegate Callback

IMKit SDK invokes this delegate when needing to display user profiles.

  1. Set the provider after SDK initialization but before server connection:
[RCIM sharedRCIM].userInfoDataSource = self;
  1. Implement the delegate method to return profile data for specific userIDs:

Method Signature

@protocol RCIMUserInfoDataSource <NSObject>

/*!
SDK callback to request user profile from the app

@param userId Target userID
@param completion Callback block returning the corresponding RCUserInfo object

@discussion The SDK uses this to fetch and display profiles. Return the requested data via the completion block.
*/
- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *userInfo))completion;

@end

Sample Code

Adapted from sealtalk-ios (GitHub · Gitee).

- (void)getUserInfoWithUserId:(NSString *)userId completion:(void (^)(RCUserInfo *userInfo))completion{
// Fetch user data asynchronously from your server
[RCDUserInfoManager getUserInfoFromServer:userId
complete:^(RCUserInfo *userInfo) {
// Return data via completion block
return completion(userInfo);
}];
}

Retrieve User Profiles

Call getUserInfoCache: to actively fetch cached profiles for specific userIDs.

The SDK checks memory caches first. If persistence is enabled (enablePersistentUserInfoCache=YES), it also queries the local database. Missing data triggers provider callbacks.

Sample Code

[[RCIM sharedRCIM] getUserInfoCache:@"userId"];

Refresh User Profiles

Use refreshUserInfoCache: to update locally cached profiles.

With persistence enabled, this also updates database records. ::: tip For performance reasons, IMKit SDK doesn't immediately refresh the current view. Changes appear when switching views. Force refresh by calling reload in conversation lists/views. :::

Sample Code

RCUserInfo *user = [[RCUserInfo alloc] initWithUserId:@"userId" name:@"userName" portrait:@"http://portrait"];

[[RCIM sharedRCIM] refreshUserInfoCache:user withUserId:user.userId];

Clear All User Profiles

Call clearUserInfoCache to purge all locally cached profiles.

With persistence enabled, this also clears database records. ::: tip Refreshing follows the same view-update behavior as profile refreshes. :::

Sample Code

[[RCIM sharedRCIM] clearUserInfoCache];

Configure Group Info

Implement the Group Info Provider (RCIMGroupInfoDataSource protocol) to supply group names and avatars.

Delegate Callback

IMKit SDK invokes this when needing to display group info.

  1. Set the provider after SDK initialization but before server connection:
[RCIM sharedRCIM].groupInfoDataSource = self;
  1. Implement the delegate to return group data for specific groupIDs:

Method Signature

@protocol RCIMGroupInfoDataSource <NSObject>

/*!
SDK callback to request group info from the app

@param groupId Target groupID
@param completion Callback block returning the corresponding RCGroup object

@discussion The SDK uses this to fetch and display group info. Return the requested data via completion block.
*/
- (void)getGroupInfoWithGroupId:(NSString *)groupId completion:(void (^)(RCGroup *groupInfo))completion;

@end

Sample Code

Adapted from sealtalk-ios (GitHub · Gitee).

- (void)getGroupInfoWithGroupId:(NSString *)groupId completion:(void (^)(RCGroup *))completion {
// Fetch group data asynchronously from your server
[RCDGroupManager getGroupInfoFromServer:groupId
complete:^(RCGroup * groupInfo) {
return completion(groupInfo);
}];
}

Retrieve Group Info

Call getGroupInfoCache: to actively fetch cached group info.

The SDK checks memory caches first. With persistence enabled, it also queries the local database. Missing data triggers provider callbacks.

Sample Code

[[RCIM sharedRCIM] getGroupInfoCache:@"groupId"];

Refresh Group Info

Use refreshGroupInfoCache: to update locally cached group info.

With persistence enabled, this also updates database records.

Method Signature

- (void)refreshGroupInfoCache:(RCGroup *)groupInfo withGroupId:(NSString *)groupId;

Parameters

ParameterTypeDescription
groupInfoRCGroupUpdated group info
groupIdNSStringGroup targetId

Sample Code

RCGroup *group = [[RCGroup alloc] initWithGroupId:@"groupId" groupName:@"groupName" portraitUri:@"http://portraitUri"];
/// v5.4.1+ adds NSString-type extra field
group.extra = @"groupExtra";
[[RCIM sharedRCIM] refreshGroupInfoCache:group withGroupId:group.groupId];

Clear All Group Info

Call clearGroupInfoCache to purge all locally cached group info.

With persistence enabled, this also clears database records.

Sample Code

[[RCIM sharedRCIM] clearGroupInfoCache];

Configure Group Member Profiles

Implement the Group Member Provider (RCIMGroupUserInfoDataSource protocol) to supply member nicknames and avatars within groups.

tip

Without this protocol, IMKit SDK defaults to using user profile protocols for group members.

Delegate Callback

IMKit SDK invokes this when needing to display member profiles in groups.

  1. Set the provider after SDK initialization but before server connection:
[RCIM sharedRCIM].groupUserInfoDataSource = self;
  1. Implement the delegate to return member data for specific groupID-userID pairs:

Method Signature

@protocol RCIMGroupUserInfoDataSource <NSObject>

/*!
SDK callback to request group member profiles from the app

@param userId Target userID
@param groupId Target groupID
@param completion Callback block returning the corresponding RCUserInfo object

@discussion For group card functionality, the SDK uses this to fetch and display member profiles.
*/
- (void)getUserInfoWithUserId:(NSString *)userId
inGroup:(NSString *)groupId
completion:(void (^)(RCUserInfo *userInfo))completion;

@end

Sample Code

Adapted from sealtalk-ios (GitHub · Gitee).

- (void)getUserInfoWithUserId:(NSString *)userId
inGroup:(NSString *)groupId
completion:(void (^)(RCUserInfo *userInfo))completion {
[RCDGroupManager getGroupMemberDetailInfoFromServer:userId
groupId:groupId
complete:^(RCUserInfo *memberInfo) {
return completion(memberInfo);
}];
}

Retrieve Member Profiles

Call getGroupUserInfoCache: to actively fetch cached member profiles.

The SDK checks memory caches first. With persistence enabled, it also queries the local database. Missing data triggers provider callbacks.

Sample Code

[[RCIM sharedRCIM] getGroupUserInfoCache:@"userId" withGroupId:@"groupId"];

Refresh Member Profiles

Use refreshGroupUserInfoCache: to update locally cached member profiles.

With persistence enabled, this also updates database records.

Method Signature

- (void)refreshGroupUserInfoCache:(RCUserInfo *)userInfo withUserId:(NSString *)userId withGroupId:(NSString *)groupId;

Parameters

ParameterTypeDescription
userInfoRCUserInfoUpdated member profile
userIdNSStringUser ID
groupIdNSStringGroup targetId

Sample Code

RCUserInfo *user = [[RCUserInfo alloc] initWithUserId:@"userId" name:@"userName" portrait:@"http://portrait"];

[[RCIM sharedRCIM] refreshGroupUserInfoCache:user withUserId:user.userId withGroupId:@"groupId"];

Clear Member Profiles

Call clearGroupUserInfoCache to purge all locally cached member profiles.

With persistence enabled, this also clears database records.

Sample Code

[[RCIM sharedRCIM] clearGroupUserInfoCache];

Configure Group Member Lists

For features like @mentions in group chats, IMKit SDK requires member lists from the application layer.

tip

IMKit SDK doesn't cache member list data.

Delegate Callback

  1. Set the provider after SDK initialization but before server connection:
[RCIM sharedRCIM].groupMemberDataSource = self;
  1. Implement the delegate to return member lists for specific groupIDs:

Method Signature

@protocol RCIMGroupMemberDataSource <NSObject>
@optional

/*!
SDK callback to request group member lists from the app

@param groupId Target groupID
@param resultBlock Callback block returning the member ID array

@discussion The SDK uses this to fetch member lists for display. Return the requested data via resultBlock.
*/
- (void)getAllMembersOfGroup:(NSString *)groupId result:(void (^)(NSArray<NSString *> *userIdList))resultBlock;
@end

Sample Code

Adapted from sealtalk-ios (GitHub · Gitee).

- (void)getAllMembersOfGroup:(NSString *)groupId result:(void (^)(NSArray<NSString *> *))resultBlock {
[RCDGroupManager getGroupMembersFromServer:groupId
complete:^(NSArray<NSString *> *_Nonnull memberIdList) {
return resultBlock(memberIdList);
}];
}