Profiles / Profile attributes |
Use the following example code to interact with Profiles attributes.
If you're going to collect dates, add the following dateFormatter to your code.
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM-dd-yyyy"];
// to set a profile attribute: [Localytics setValue:@45 forProfileAttribute:@"Age" withScope:LLProfileScopeOrganization]; [Localytics setValue:@[@8, @13] forProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication]; [Localytics setValue:[dateFormatter dateFromString:@"11-23-1962"] forProfileAttribute:@"Birthday" withScope:LLProfileScopeOrganization]; [Localytics setValue:@[[dateFormatter dateFromString:@"10-01-2015"], [dateFormatter dateFromString:@"03-17-2016"]] forProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication]; [Localytics setValue:@"New York, New York" forProfileAttribute:@"Hometown" withScope:LLProfileScopeOrganization]; [Localytics setValue:@[@"New York", @"California", @"South Dakota"] forProfileAttribute:@"States visited" withScope:LLProfileScopeApplication]; // to remove a profile attribute: [Localytics deleteProfileAttribute:@"Days until graduation" withScope:LLProfileScopeApplication]; // to add a set of values to an already-defined set of values: [Localytics addValues:@[@222] toSetForProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication]; [Localytics addValues:@[[dateFormatter dateFromString:@"04-19-2015"], [dateFormatter dateFromString:@"12-24-2015"]] toSetForProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication]; [Localytics addValues:@[@"North Dakota"] toSetForProfileAttribute:@"States visited" withScope:LLProfileScopeApplication]; // to remove a set of values from an already-defined set of values: [Localytics removeValues:@[@8, @222] fromSetForProfileAttribute:@"Lucky numbers" withScope:LLProfileScopeApplication]; [Localytics removeValues:@[[dateFormatter dateFromString:@"03-17-2016"]] fromSetForProfileAttribute:@"Upcoming sales calls" withScope:LLProfileScopeApplication]; [Localytics removeValues:@[@"California"] fromSetForProfileAttribute:@"States visited" withScope:LLProfileScopeApplication]; // to increment or decrement an already-defined value: [Localytics incrementValueBy:1 forProfileAttribute:@"Age" withScope:LLProfileScopeOrganization]; [Localytics decrementValueBy:3 forProfileAttribute:@"Days until graduation" withScope:LLProfileScopeApplication];