Update your profile
Update the signed-in user’s profile with OpenIM iOS SDK.
Update the signed-in user's profile attributes using setSelfInfo:onSuccess:onFailure:. First retrieve the existing user snapshot with Retrieve your profile and mutate only the intended fields (e.g., nickname, faceURL, or ex). Avoid passing an uninitialized model object, as default unassigned fields may overwrite existing profile data on the server.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
userInfo | OIMUserInfo * | Yes | User information object containing the modified profile fields. |
Code example
current.nickname = nickname;
current.faceURL = avatarURL;
[[OIMManager manager] setSelfInfo:current
onSuccess:^(NSString *data) {
[profileStore refreshCurrentUserInfo:current];
}
onFailure:^(NSInteger code, NSString *message) {
NSLog(@"setSelfInfo failed: %ld %@", (long)code, message);
}];The ex attribute is replaced as an entire string. Parse existing JSON metadata, update your business properties, and re-serialize the string before assigning it.
Return value
The onSuccess callback signifies that OpenIMServer processed the profile update. The local client can immediately refresh its visible view state. Multi-terminal sync and cross-device propagation are received asynchronously through the user delegate.
State changes after the call
- Local state merge: Merge profile attributes using the authenticated user's
userIDas the unique entity key. - Asynchronous event listening: Multi-terminal devices and local caches observe updates via
onSelfInfoUpdated:inOIMUserListener. - Re-query calibration: If delegate delivery fails or local cache becomes desynchronized, invoke
getSelfInfoWithOnSuccess:onFailure:to restore an authoritative profile snapshot.
@interface ProfileStore () <OIMUserListener>
@end
@implementation ProfileStore
- (void)startListening {
[[OIMManager callbacker] addUserListener:self];
}
- (void)stopListening {
[[OIMManager callbacker] removeUserListener:self];
}
- (void)onSelfInfoUpdated:(OIMUserInfo *)info {
[self updateLocalCurrentUser:info];
}
@endRetain this listener instance strongly, and invoke removeUserListener: with the same reference when logging out or switching user accounts.
Was this page helpful?