Set User Attributes in iOS
Learn about setting user attributes in iOS
User attributes, also referred to as profile properties and custom properties, are a set of key/value pairs that are specific to your application domain.
The system stores these key/value pairs under the properties field of an appUser. The attributes may have values of type Number, String, or Boolean.
We strongly recommend setting user attributes on your app user as directly after login. Any properties set before logging in are set to an anonymous entity and merged after the login has occurred. This merging may introduce undesired results.
Key attributes to set include first name, last name, and email address.
Attributes are listed under userProperties
and then to KBMuser.current()
after they have been defined. In our example, we've laid out our recommended order and method of introducing these attributes.
BrandMessengerManager.login("accessToken") { response, error in
if let err = error {
print("BrandMessenger login failed with an error: ", err.localizedDescription)
return
}
let authorProperties = NSMutableDictionary()
authorProperties.setValue("ios", forKey: "platform")
KBMUserClientService().updateUserDisplayName(nil, andUserImageLink: nil, userStatus: nil, metadata: authorProperties) { response, error in
if let err = error {
print("failed to update the user meta data")
return
}
}
print("BrandMessenger login successful")
}
BrandMessengerManager login:@"accessToken" completion:^(KBMRegistrationResponse * _Nullable response, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"BrandMessenger login failed with an error: %@", error.localizedDescription);
return;
}
NSMutableDictionary *authorProperties = [NSMutableDictionary new];
[authorProperties setObject:@"ios" forKey:@"platform"];
[[[KBMUserClientService alloc] init] updateUserDisplayName:nil
andUserImageLink:nil
userStatus:nil
metadata:authorProperties
withCompletion:^(id response, NSError *error) {
if (error != nil) {
NSLog(@"Failed to update the user meta data"")
return;
}
}];
NSLog(@"BrandMessenger login successful");
}];
Metadata also needs to be defined in Metadata Visibility. You can find this within the Admin by navigating to Khoros Response > Admin and selecting Metadata Visibility in the sidebar.

Then, simply scroll down to the Display Fields in Author Profile and add Brand Messenger if it's not already present. You can then define Metadata Fields and the display name they will appear within the conversation in Agent view.
Updating Author Properties
After logging in to the SDK, you can update author properties in care as follows:
let authorProperties = NSMutableDictionary()
authorProperties.setValue("ios", forKey: "platform")
KBMUserClientService().updateUserDisplayName(nil, andUserImageLink: nil, userStatus: nil, metadata: authorProperties) {
response, error in
if let err = error {
print("failed to update the user meta data")
return
}
}
NSMutableDictionary *authorProperties = [NSMutableDictionary new];
[authorProperties setObject:@"ios" forKey:@"platform"];
[[[KBMUserClientService alloc] init] updateUserDisplayName:nil andUserImageLink:nil userStatus:nil metadata:authorProperties withCompletion:^(id response, NSError *error) {
if (error != nil) {
NSLog(@"Failed to update the user meta data"")
return;
}
}];
Updated 7 months ago