User Profile Hosting
This document helps developers understand how to implement user profile subscription, querying, and monitoring in RC's iOS client SDK, along with modifying and querying user profiles and permissions.
Through this guide, you'll learn how to retrieve and track user profiles, and receive notifications when profile changes or subscription status updates occur.
This feature is supported starting from version 5.10.0.
Enabling the Service
Before using this feature, you must enable the profile hosting service by submitting a ticket.
Manage User Profiles
RC IMLib SDK provides interfaces for querying user profiles, subscribing to updates, and modifying your own profile information.
Set User Profile
Use the updateMyUserProfile:success:error:
interface to modify your profile. Configure profile attributes by creating an RCUserProfile
object.
By default, your profile information won't undergo moderation. To enable content review, go to [Console] > App Configuration > Security & Moderation > IM & RTC Moderation > IM Profile Hosting Configuration, then enable and configure the content requiring review.
Interface Prototype
- (void)updateMyUserProfile:(RCUserProfile *)profile
successBlock:(void (^)(void))successBlock
errorBlock:(nullable void (^)(RCErrorCode errorCode, NSArray<NSString *> * _Nullable errorKeys))errorBlock;
Parameter Description
[RCUserProfile] attributes:
Attribute | Type | Description |
---|---|---|
name | NSString | Nickname (max 32 characters) |
portraitUri | NSString | Avatar URL (max 128 characters) |
uniqueId | NSString | User application ID (supports alphanumeric characters, max 32 chars). Note: Client SDK doesn't support setting this field. |
NSString | Email (max 128 characters) | |
birthday | NSString | Birthday (max 32 characters) |
gender | RCUserGender | Gender |
location | NSString | Location (max 32 characters) |
role | NSUInteger | Role (0-100) |
level | NSUInteger | Level (0-100) |
userExtProfile | NSDictionary<NSString *, NSString *> | Custom extended information (max 20 key-value pairs). Keys must be predefined in developer console:
|
Example Code
RCUserProfile *userProfile = [[RCUserProfile alloc] init];
userProfile.name = @"name";
[[RCCoreClient sharedCoreClient] updateMyUserProfile:userProfile success:^{
// Update successful
} error:^(RCErrorCode errorCode, NSArray<NSString *> * _Nullable errorKeys) {
// Update failed
// When errorCode == RC_SERVICE_INFORMATION_AUDIT_FAILED, errorKeys returns rejected attribute names (e.g., name)
}];
Get Current User Profile
Use getMyUserProfile:error:
to retrieve your own profile information.
Example Code
[[RCCoreClient sharedCoreClient] getMyUserProfile:^(RCUserProfile *userProfile) {
// Retrieval successful
} error:^(RCErrorCode errorCode) {
// Retrieval failed
}];
Batch Get Other Users' Profiles
Use getUserProfiles:success:error:
to query specific users' profiles by providing their userIds.
- Maximum 20 userIds per query.
Example Code
NSArray *userIds = @[@"userId1", @"userId2"];
[[RCCoreClient sharedCoreClient] getUserProfiles:userIds success:^(NSArray<RCUserProfile *> *userProfiles) {
// Retrieval successful
} error:^(RCErrorCode errorCode) {
// Retrieval failed
}];
Manage User Permissions
RC IMLib SDK provides interfaces for setting and retrieving user-level permissions through the RCUserProfileVisibility
enum.
[RCUserProfileVisibility] enum:
Value | Permission |
---|---|
RCUserProfileVisibilityNotSet | Not set: Follows AppKey-level permissions (default) |
RCUserProfileVisibilityInvisible | Invisible: Others can only see your name and avatar |
RCUserProfileVisibilityEveryone | Everyone: All users under this AppKey can view your profile |
Permission Explanation
Default AppKey-level permission is Invisible, while user-level defaults to Not set. When both remain default, others can only see your name and avatar.
Combined permission behavior:
AppKey-Level Permission | User-Level Permission | Result |
---|---|---|
Invisible/Friends Only/Everyone | Not set | Follows AppKey-level permission |
Invisible/Friends Only/Everyone | Explicitly set (Invisible/Friends Only/Everyone) | Follows user-level permission |
Set User Permission
Use updateMyUserProfileVisibility:success:error
to configure your profile visibility.
Example Code
[[RCCoreClient sharedCoreClient] updateMyUserProfileVisibility:RCUserProfileVisibilityEveryone success:^{
// Update successful
} error:^(RCErrorCode errorCode) {
// Update failed
}];
Get User Permission
Use getMyUserProfileVisibility:
to retrieve your current visibility setting.
Example Code
[[RCCoreClient sharedCoreClient] getMyUserProfileVisibility:^(RCUserProfileVisibility visibility) {
// Retrieval successful
} error:^(RCErrorCode errorCode) {
// Retrieval failed
}];
Use searchUserProfileByUniqueId:success:error
to search for users by their application ID:
Example Code
// Query user info using application ID
[[RCCoreClient sharedCoreClient] searchUserProfileByUniqueId:@"uniqueId" success:^(RCUserProfile * _Nonnull userProfile) {
// Query successful
} error:^(RCErrorCode errorCode) {
// Query failed
}];
User Profile & Permission Change Subscriptions
Listen for Subscription Events
To receive real-time notifications about subscription changes, you must set up the subscription event listener delegate after initializing the IMLib SDK but before establishing the connection. Implement the relevant delegate methods from the RCSubscribeEventDelegate
protocol.
// Add listener delegate
[[RCCoreClient sharedCoreClient] addSubscribeEventDelegate:self];
// Remove listener delegate
[[RCCoreClient sharedCoreClient] removeSubscribeEventDelegate:self];
- Starting from version 5.10.0, RCSubscribeType includes two subscription types: RCSubscribeTypeOnlineStatus(1) for online status and RCSubscribeTypeUserProfile(2) for User Profile Hosting.
- Starting from version 5.12.0, RCSubscribeType adds two new types: RCSubscribeTypeFriendOnlineStatus(3) for friend online status and RCSubscribeTypeFriendUserProfile(4) for friend user profile hosting.
Implement the delegate:
-
After successfully connecting to IM, the IMLib SDK automatically synchronizes subscription data changes. When subscription data is successfully synced to the local device or system, the following method is triggered where you can execute subsequent business logic.
/// Deprecated - use onSubscriptionSyncCompleted: instead
- (void)onSubscriptionSyncCompleted;
/// Subscription data sync completed
/// Use type to distinguish between different subscription types. When type equals RCSubscribeTypeOnlineStatus, it represents online status subscription events.
/// - Since: 5.10.0
- (void)onSubscriptionSyncCompleted:(RCSubscribeType)type; -
When subscription events change, implement this method to handle event changes, such as updating the user interface or processing new data. This method is typically called on a background thread, so switch to the main thread for UI updates.
subscribeEvents
contains a list of all changed events. Note: Subscription expiration doesn't trigger notifications, so you need to track expiration times manually./// Note: Starting from version 5.10.0, check RCSubscribeInfoEvent's subscribeType. When it equals RCSubscribeTypeOnlineStatus, it represents online status subscription events.
- (void)onEventChange:(NSArray<RCSubscribeInfoEvent *> *)subscribeEvents; -
When subscription information changes on other devices, implement this method to update status information on the current device, ensuring subscription consistency.
subscribeEvents
contains a list of changed subscription events./// Starting from version 5.10.0, check RCSubscribeEvent's subscribeType. When it equals RCSubscribeTypeOnlineStatus, it represents online status subscription events.
- (void)onSubscriptionChangedOnOtherDevices:(NSArray<RCSubscribeEvent *> *)subscribeEvents;
Subscribe to User Profile & Permission Changes
To track changes in other users' profiles and permissions, use the subscribeEvent:completion:
method to subscribe to user profile change events.
- Create a subscription request object
RCSubscribeEventRequest
, set the subscription type toRCSubscribeTypeUserProfile
, specify the user IDs to subscribe to, and set the subscription duration. Note: You can subscribe to up to 200 users at once, with a maximum of 1000 subscribed users, and you can be subscribed by up to 5000 users.
RCSubscribeEventRequest *request = [[RCSubscribeEventRequest alloc] init];
// List of users to subscribe to
request.userIds = @[@"userId1", @"userId2"];
// Subscription type
request.subscribeType = RCSubscribeTypeUserProfile;
// Subscription duration in seconds
request.expiry = 180000;
- Call
subscribeEvent:completion:
with the configuredRCSubscribeEventRequest
object to execute the subscription.
[[RCCoreClient sharedCoreClient] subscribeEvent:request completion:^(RCErrorCode status, NSArray<NSString *> * _Nullable failedUserIds) {
if (RC_SUCCESS == status) {
// Subscription successful
}
}];
Unsubscribe from User Profile & Permission Changes
- When you no longer need to track changes for subscribed users, create a
RCSubscribeEventRequest
object, set the subscription type toRCSubscribeTypeUserProfile
, and specify the user IDs to unsubscribe from. Note: You can unsubscribe from up to 200 users at once.
RCSubscribeEventRequest *request = [[RCSubscribeEventRequest alloc] init];
request.subscribeType = RCSubscribeTypeUserProfile;
request.userIds = @[@"userId1", @"userId2"];
- Call
unSubscribeEvent:completion:
with the configuredRCSubscribeEventRequest
object to unsubscribe from the specified users.
[[RCCoreClient sharedCoreClient] unSubscribeEvent:request completion:^(RCErrorCode status, NSArray<NSString *> * _Nullable failedUserIds) {
if (RC_SUCCESS == status) {
// Unsubscription successful
}
}];
Query User Profile & Permission Subscription Status
- To query subscription status for specific users, create a
RCSubscribeEventRequest
object, set the subscription type toRCSubscribeTypeUserProfile
, and specify the user IDs to query. Note: You can query up to 200 users at once.
RCSubscribeEventRequest *request = [[RCSubscribeEventRequest alloc] init];
request.subscribeType = RCSubscribeTypeUserProfile;
request.userIds = @[@"userId1", @"userId2"];
- Call
querySubscribeEvent:completion:
with the configuredRCSubscribeEventRequest
object to query subscription status for the specified users.
ll specified users.
```objectivec
[[RCCoreClient sharedCoreClient] querySubscribeEvent:request completion:^(RCErrorCode status, NSArray<RCSubscribeInfoEvent *> * _Nullable subscribeEvents) {
if (RC_SUCCESS == status) {
// Query succeeded
}
}];
Paginated query for subscribed user profiles & permission changes
- To paginate through all subscribed users' profiles and permission changes, create an
RCSubscribeEventRequest
object and set the subscription type toRCSubscribeTypeUserProfile
.
RCSubscribeEventRequest *request = [[RCSubscribeEventRequest alloc] init];
request.subscribeType = RCSubscribeTypeUserProfile;
- Call
querySubscribeEvent:pageSize:startIndex:completion:
with the configuredRCSubscribeEventRequest
object, specifying pagination parameters:
pageSize
: Number of users per page (1-200)startIndex
: Starting index (0 for first page, then increment by previous page's count - e.g., set to 20 for second page if pageSize=20)
[[RCCoreClient sharedCoreClient] querySubscribeEvent:request
pageSize:20
startIndex:0
completion:^(RCErrorCode status, NSArray<RCSubscribeInfoEvent *> * _Nullable subscribeEvents) {
if (RC_SUCCESS == status && subscribeEvents.count > 0) {
// Query succeeded
}
}];