13.4. Retrieving Properties of Address Book Entries
Problem
You have retrieved a reference to an item in the address book, such as a person’s entry, and you want to retrieve that person’s properties, such as first and last names.
Solution
Use the ABRecordCopyValue
function on the person’s Address Book record.
Discussion
The records in the address book database are of type ABRecordRef. Each record could be either a
group or a person. We have not discussed groups yet, so let’s focus on
people. Each person could have various types of information assigned to
him, such as his first name, last name, email address, and so on. Bear
in mind that many of these values are optional, and at the time of
creating a new contact in the address book database, the user can simply
leave out fields such as phone number, middle name, email address, URL,
and so forth.
ABRecordCopyValue accepts an
address book record and the property that has to be retrieved as its two
parameters. The second parameter is the property of the record that we
want to retrieve. Here are some of the common properties (all of these
properties are defined as constant values in the ABPerson.h header file):
kABPersonFirstNamePropertyThis value will retrieve the first name of the given person. The return value is of type
CFStringRef, which can be cast toNSStringwith a bridge cast, so you can do just about anything you want with the results.kABPersonLastNamePropertyThis value will retrieve the last name of the given person. Like the first ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access