User profiles
This guide covers managing user profiles, including setting, querying, and subscribing to profile changes.
tip
All user profile APIs are on the NCEngine.userModule object, not directly on NCEngine.
Update your profile
Call updateMyUserProfile:completion: on NCEngine.userModule. Pass the fields you want to update — nil fields are not modified.
- Swift
- Objective-C
swift
import NexconnChatSDK
let userProfile = UserProfile()
userProfile.name = "Display Name"
NCEngine.userModule.updateMyUserProfile(userProfile) { errorKeys, error in
if error == nil {
// Updated successfully
} else {
// errorKeys: field-level error keys returned on partial failure
}
}
Objective C
NCUserProfile *userProfile = [[NCUserProfile alloc] init];
userProfile.name = @"Display Name";
[[NCEngine userModule] updateMyUserProfile:userProfile
completion:^(NSArray<NSString *> *errorKeys, NCError *error) {
if (!error) {
// Updated successfully
} else {
// errorKeys: field-level error keys returned on partial failure
}
}];
Get your profile
- Swift
- Objective-C
swift
import NexconnChatSDK
NCEngine.userModule.getMyUserProfile { userProfile, error in
if error == nil {
print("Name: \(userProfile?.name ?? "")")
}
}
Objective C
[[NCEngine userModule] getMyUserProfileWithCompletion:^(NCUserProfile *userProfile, NCError *error) {
if (!error) {
NSLog(@"Name: %@", userProfile.name);
}
}];
Get other users' profiles
Query up to 20 users per call:
- Swift
- Objective-C
swift
import NexconnChatSDK
NCEngine.userModule.getUserProfiles(userIds: ["userId1", "userId2"]) { profiles, error in
// profiles: list of user profiles
}
Objective C
[[NCEngine userModule] getUserProfilesWithUserIds:@[@"userId1", @"userId2"]
completion:^(NSArray<NCUserProfile *> *profiles, NCError *error) {
// profiles: list of user profiles
}];
Profile visibility
Set visibility
- Swift
- Objective-C
swift
import NexconnChatSDK
NCEngine.userModule.updateMyUserProfileVisibility(.everyone) { error in
if error == nil {
// Set successfully
}
}
Objective C
[[NCEngine userModule] updateMyUserProfileVisibility:NCUserProfileVisibilityEveryone
completion:^(NCError *error) {
if (!error) {
// Set successfully
}
}];
| Value | Description |
|---|---|
NCUserProfileVisibilityNotSet | Not set — uses App Key-level setting (default) |
NCUserProfileVisibilityInvisible | Hidden — no one can see profile details except name and avatar |
NCUserProfileVisibilityFriendVisible | Visible to confirmed friends only |
NCUserProfileVisibilityEveryone | Public — all users can view your profile |
Get visibility
- Swift
- Objective-C
swift
import NexconnChatSDK
NCEngine.userModule.getMyUserProfileVisibility { visibility, error in
// visibility: current setting
}
Objective C
[[NCEngine userModule] getMyUserProfileVisibilityWithCompletion:^(NCUserProfileVisibility visibility, NCError *error) {
// visibility: current setting
}];
Subscribe to profile changes
Register a user event handler
Register an NCUserHandler to receive subscription events:
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyUserHandler: NSObject, UserHandler {}
let userHandler = MyUserHandler()
NCEngine.addUserHandler(identifier: "YourKey", handler: userHandler)
Objective C
[NCEngine addUserHandlerWithIdentifier:@"YourKey" handler:self];
Subscribe
Max 200 users per call, 1,000 total subscriptions:
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = SubscribeEventParams(subscribeType: .userProfile, userIds: ["userId1", "userId2"])
// Set subscribeType and expiry as needed
NCEngine.userModule.subscribeEvent(params: params) { failedUserIds, error in
// failedUserIds: IDs that failed to subscribe (empty on full success)
}
Objective C
NCSubscribeEventParams *params = [[NCSubscribeEventParams alloc] init];
params.userIds = @[@"userId1", @"userId2"];
// Set subscribeType and expiry as needed
[[NCEngine userModule] subscribeEventWithParams:params
completion:^(NSArray<NSString *> *failedUserIds, NCError *error) {
// failedUserIds: IDs that failed to subscribe (empty on full success)
}];
Unsubscribe
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = UnsubscribeEventParams(subscribeType: .userProfile, userIds: ["userId1", "userId2"])
NCEngine.userModule.unsubscribeEvent(params: params) { failedUserIds, error in
// Unsubscribed
}
Objective C
NCUnsubscribeEventParams *params = [[NCUnsubscribeEventParams alloc] init];
params.userIds = @[@"userId1", @"userId2"];
[[NCEngine userModule] unsubscribeEventWithParams:params
completion:^(NSArray<NSString *> *failedUserIds, NCError *error) {
// Unsubscribed
}];
Query subscription events
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = GetSubscribeEventParams()
params.subscribeType = .userProfile
params.userIds = ["userId1", "userId2"]
NCEngine.userModule.getSubscribeEvent(params: params) { events, error in
// events: subscription event list
}
Objective C
NCGetSubscribeEventParams *params = [[NCGetSubscribeEventParams alloc] init];
params.userIds = @[@"userId1", @"userId2"];
[[NCEngine userModule] getSubscribeEventWithParams:params
completion:^(NSArray<NCSubscriptionStatusInfo *> *events, NCError *error) {
// events: subscription event list
}];