Adding Properties to Address Book Records
You can add your own properties to the people and groups in the address book. For example, if you’re creating a small application to manage a dog club, you could add properties to each person that specify the name and breed of that person’s dog. Or if you’re creating an application to manage business contacts, you could add a property that lists all the meetings and phone calls a user has had with that person. These properties are stored in the Address Book database. Applications that don’t know about the new properties aren’t affected by them and don’t modify them.
When deciding whether to add a property to the Address Book record, keep these issues in mind:
Avoid properties for confidential information, such as credit card numbers. The Address Book framework does not provide any security above what’s provided by OS X. Anyone who has read and write access to a user’s home folder can also read and write that user’s address book.
Avoid properties that are not useful for everyone in the address book database. If you want to store information for just the logged-in user, for Cocoa applications refer to NSUserDefaults Class Reference, and for C-based applications refer to Preferences Utilities Reference.
Use a multivalue list if you think a person may have more than one of that property. Your new multivalue list has the same capabilities as the other multivalue lists in the address book. The user can choose a primary value in the list and can create distribution lists for it.
To add properties to every person or group, use the
ABGroup class method
addPropertiesAndTypes:. These procedures take a dictionary, in which the keys are the names of the new properties and the values are their types. Note that the property names must be unique. You may want to use reverse-DNS style names for your properties, to make sure no one else uses the same name; for example,
com.mycompany.buildingNumber. The type can be one of the types or a multivalue list of one of the types listed in Property Types.
The following code listing adds a custom property, and then removes it:
NSNumber* stringProperty = [NSNumber numberWithInteger:kABStringProperty];
NSString* testProperty = @"com.example.myProperty";
NSDictionary* dict = [NSDictionary dictionaryWithObject:stringProperty
NSInteger result = [ABPerson addPropertiesAndTypes:dict];
NSLog(@"Added %d properties.", result);
result = [ABPerson removeProperties:[NSArray arrayWithObject:testProperty]];
NSLog(@"Removed %d properties.", result);