AppboyKit (also known as the Objective-C SDK) is no longer supported and has been replaced by the Swift SDK. It will no longer receive new features, bug fixes, security updates, or technical support—however, messaging and analytics will continue to function as normal. To learn more, see Introducing the New Braze Swift SDK.
Setting custom attributes for iOS
Braze provides methods for assigning attributes to users. You’ll be able to filter and segment your users according to these attributes on the dashboard.
Before implementation, be sure to review examples of the segmentation options afforded by custom events, custom attributes, and purchase events in our best practices, as well as our notes on event naming conventions.
Assigning default user attributes
To assign user attributes, you need to set the appropriate field on the shared ABKUser object.
The following is an example of setting the first name attribute:
The following attributes should be set on the ABKUser object:
firstName
lastName
email
dateOfBirth
country
language
homeCity
phone
userID
gender
Assigning custom user attributes
Beyond the default user attributes, Braze also allows you to define custom attributes using several different data types. See our user data collection for more information on the segmentation options each of these attributes will afford you.
Dates passed to Braze with this method must either be in the ISO 8601 format (e.g 2013-07-16T19:20:30+01:00) or in the yyyy-MM-dd'T'HH:mm:ss:SSSZ format (2016-12-14T13:32:31.601-0800).
The maximum number of elements in custom attribute arrays defaults to 25. Arrays exceeding the maximum number of elements will be truncated to contain the maximum number of elements. The maximum for individual arrays can be increased to up to 100. If you would like this maximum increased, reach out to your customer service manager.
// Setting a custom attribute with an array value[[AppboysharedInstance].usersetCustomAttributeArrayWithKey:@"array_name"array:@[@"value1",@"value2"]];// Adding to a custom attribute with an array value[[AppboysharedInstance].useraddToCustomAttributeArrayWithKey:@"array_name"value:@"value3"];// Removing a value from an array type custom attribute[[AppboysharedInstance].userremoveFromCustomAttributeArrayWithKey:@"array_name"value:@"value2"];// Removing an entire array and key[[AppboysharedInstance].usersetCustomAttributeArrayWithKey:@"array_name"array:nil];
1
2
3
4
5
6
// Setting a custom attribute with an array valueAppboy.sharedInstance()?.user.setCustomAttributeArrayWithKey("array_name",array:["value1","value2"])// Adding to a custom attribute with an array valueAppboy.sharedInstance()?.user.addToCustomAttributeArrayWithKey("array_name",value:"value3")// Removing a value from an array type custom attributeAppboy.sharedInstance()?.user.removeFromCustomAttributeArrayWithKey("array_name",value:"value2")
Unsetting a custom attribute
Custom attributes can also be unset using the following method:
This code is an example of an incrementing custom attribute. You may increment the value of a custom attribute by any positive or negative integer or long value:
To set up a subscription for your users (either email or push), call the functions setEmailNotificationSubscriptionType or setPushNotificationSubscriptionType, respectively. Both of these functions take the enum type ABKNotificationSubscriptionType as arguments. This type has three different states:
Subscription Status
Definition
ABKOptedin
Subscribed, and explicitly opted in
ABKSubscribed
Subscribed, but not explicitly opted in
ABKUnsubscribed
Unsubscribed and/or explicitly opted out
Users who grant permission for an app to send them push notifications default to the status of ABKOptedin as iOS requires an explicit opt-in.
Users will be set to ABKSubscribed automatically upon receipt of a valid email address; however, we suggest that you establish an explicit opt-in process and set this value to OptedIn upon receipt of explicit consent from your user. Refer to Managing user subscriptions for more details.