Next Page > Hide TOC

ABPerson Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AddressBook.framework
Availability
Available in Mac OS X v10.2 and later.
Declared in
ABImageLoading.h
ABPerson.h
Companion guides
Related sample code

Overview

The ABPerson class encapsulates all information about a person in the Address Book database—an instance of ABPerson corresponds to a single person record in the database. The ABPerson class defines properties such as the person’s name, company, address, email addresses, and phone numbers.

Some of these properties have multiple values that are accessed via standard and user-defined labels. For example, a person may have a home, work, mobile, and fax phone numbers. Therefore, the phone attribute is defined as an ABMultiValue object containing NSString objects for each number. For example, you might get a person’s primary phone number as follows:

ABMultiValue *phones = [aPerson valueForProperty:kABPhoneProperty];
id value = [phones valueAtIndex:[phones indexForIdentifier:
                [phones primaryIdentifier]]];

See ABRecord for common methods to get and set properties. See the “Constants” section for a list of all the properties, labels, and keys used to access fields in a person record. See ABMultiValue for more details on multi-value lists and how primary values work.

You can add your own properties to person records too using the addPropertiesAndTypes: method—that is, attach additional program-defined data to each person record. Because the Address Book database is stored as a property list, these program-defined properties can be ignored by other applications. Note that the AddressBook database is accessed by multiple application and is not encrypted so your application should not store any sensitive information in the database like credit card numbers.

A person may also have an associated picture or image. The image is not actually stored in the Address Book database (a property list)—it’s stored in a separate image file. You can set a person’s image using the setImageData: method, or get an image using the imageData method. Use the NSImage initWithData: method to convert an NSData object, returned by the imageData method, to an NSImage object.

Image files may be local or remote. Local images are any images in .../Library/Images/People or images the user has set using the Address Book application. Remote images are images stored on the network. These images take time to download, so ABPerson provides an asynchronous API for fetching remote images.

Use the beginLoadingImageDataForClient: method if an image file is not local and you want to perform an asynchronous fetch. You pass a client object that implements the ABImageClient protocol as an argument to this method. The beginLoadingImageDataForClient: method will return an image tracking number. A consumeImageData:forTag: message is sent to your client object when the fetch is done. Implement this method to handle the new fetched image. Use the cancelLoadingImageDataForTag:class method if for some reason you want to cancel an asynchronous fetch.

Person records may belong to multiple groups. Use the parentGroups method to get the groups a person belongs to. See ABGroup for more information about groups.

You can also search for records matching a particular “query” you specify by creating an ABSearchElement object. Use the searchElementForProperty:label:key:value:comparison: method to create an ABSearchElement object containing your query. Then use the ABAddressBook recordsMatchingSearchElement: method, passing the ABSearchElement as the argument, to query the database. See ABSearchElement for more methods that create compound queries.

Your application can also import and export persons in the vCard file format using the initWithVCardRepresentation:and vCardRepresentation methods.

The ABPerson class is “toll-free bridged” with its procedural C, opaque type, counterpart. This means that the ABPersonRef type is interchangeable in function or method calls with instances of the ABPerson class.

Tasks

Managing Properties

Managing Groups

Managing Images

Searching

Importing and Exporting VCard Formatted Files

Getting Identity Properties

Class Methods

addPropertiesAndTypes:

+ (NSInteger)addPropertiesAndTypes:(NSDictionary *)properties

Discussion

Adds the given properties to all the records of this type in the Address Book database, and returns the number of properties successfully added. In each dictionary entry, the key is a string with the property’s name, and the value is a constant with the property’s type. The property’s name must be unique. You may want to use Java-style package names for your properties, for example, "org.dogclub.dogname" or "com.mycompany.customerID". The property type must be one of the constants described in “Constants” in ABRecord. Returns -1 if an error occurs.

Availability
Declared In
ABPerson.h

cancelLoadingImageDataForTag:

+ (void)cancelLoadingImageDataForTag:(NSInteger)tag

Discussion

Cancels an asynchronous fetch of the images for a given tag. The tag argument should have been returned from a previous call to the beginLoadingImageDataForClient: method.

Availability
See Also
Declared In
ABImageLoading.h

properties

+ (NSArray *)properties

Discussion

Returns an array of the names of all the properties for the ABPerson record in the Address Book database.

Availability
See Also
Declared In
ABPerson.h

removeProperties:

+ (NSInteger)removeProperties:(NSArray *)properties

Discussion

Removes the given properties from all the records of this type in the Address Book database, and returns the number of properties successfully removed. Returns -1 if an error occurs.

Availability
Declared In
ABPerson.h

searchElementForProperty:label:key:value:comparison:

+ (ABSearchElement *)searchElementForProperty:(NSString *)property label:(NSString *)label key:(NSString *)key value:(id)value comparison:(ABSearchComparison)comparison

Discussion

Returns a search element object that specifies a query for records of this type.

Availability
See Also
Related Sample Code
Declared In
ABPerson.h

typeOfProperty:

+ (ABPropertyType)typeOfProperty:(NSString *)property

Discussion

Returns the type for a given property. If the property does not exist, this method returns kABErrorInProperty.

Availability
See Also
Declared In
ABPerson.h

Instance Methods

beginLoadingImageDataForClient:

- (NSInteger)beginLoadingImageDataForClient:(id <ABImageClient>)client

Discussion

Starts an asynchronous fetch for image data in all locations, and returns a non-zero tag for tracking. The client object should conform to the ABImageClient protocol. A consumeImageData:forTag: message is sent to client when the fetch is done. Use the cancelLoadingImageDataForTag: method if you need to cancel an asynchronous fetch.

Availability
See Also
Declared In
ABImageLoading.h

identity

Returns the CSIdentityRef object associated with a person.

- (CSIdentityRef)identity

Return Value

A CSIdentityRef object associated with the receiver or NULL if it doesn’t exist.

See Also

identityUniqueId

Returns the unique identifier for a person.

- (NSString*)identityUniqueId

Return Value

A unique identifier for the receiver or nil if it doesn’t exist.

See Also

imageData

- (NSData *)imageData

Discussion

Returns data that contains a picture of this person. This method searches only the local file system and operates synchronously. To perform an asynchronous search or to search over a network, use beginLoadingImageDataForClient:.

The returned data is in a QuickTime-compatible format. To create an image from it, use the NSImage method initWithData:.

Availability
See Also
Declared In
ABImageLoading.h

initWithVCardRepresentation:

- (id)initWithVCardRepresentation:(NSData *)vCardData

Discussion

Returns an ABPerson instance initialized with the given data. If vCardData is nil or is not a valid vCard format, this method returns nil.

Availability
See Also
Declared In
ABPerson.h

parentGroups

- (NSArray *)parentGroups

Discussion

Returns an array of the ABGroups this person belongs to. If the person doesn’t belong to any groups, this method returns an empty array.

Availability
Declared In
ABPerson.h

setImageData:

- (BOOL)setImageData:(NSData *)data

Discussion

Sets the image for this person to the given data. The data argument must be in a QuickTime-compatible format. Pass nil to specify that there is no image for this person.

Availability
See Also
Declared In
ABImageLoading.h

vCardRepresentation

- (NSData *)vCardRepresentation

Discussion

Returns the vCard representation of the person as a data object in vCard format.

Availability
See Also
Declared In
ABPerson.h

Constants

These are the properties that an ABPerson record contains by default. ABRecord describes additional properties that all records contain, in “Constants”. Note that some of these properties are not displayed in the Address Book application. Developers can add their own properties with the ABRecord method addPropertiesAndTypes:.

Note: The kABHomePageProperty property has been deprecated in Mac OS X version 10.4. Instead, use the kABURLsProperty multi-value property.

Constant

Description

kABFirstNameProperty

First name (NSString)

kABLastNameProperty

Last name (NSString)

kABFirstNamePhoneticProperty

Phonetic representation of the first name (NSString)

kABLastNamePhoneticProperty

Phonetic representation of the last name (NSString)

kABBirthdayProperty

Birth date (NSDate)

kABOrganizationProperty

Company name (NSString)

kABJobTitleProperty

Job title (NSString)

kABHomePageProperty

Home web page (NSString)

kABURLsProperty

Web pages(ABMultiValue containing NSString)

kABCalendarURIsProperty

Calendar URIs(ABMultiValue containing NSString)

kABEmailProperty

Email addresses (ABMultiValue containing NSString)

kABAddressProperty

Street addresses (ABMultiValue containing NSDictionary)

kABPhoneProperty

Generic phone number (ABMultiValue containing NSString)

kABAIMInstantProperty

AOL instant messaging ID (ABMultiValue containing NSString)

kABJabberInstantProperty

Jabber instant messaging ID (ABMultiValue containing NSString)

kABMSNInstantProperty

MSN instant messaging ID (ABMultiValue containing NSString)

kABYahooInstantProperty

Yahoo instant messaging ID (ABMultiValue containing NSString)

kABICQInstantProperty

ICQ instant messaging ID (ABMultiValue containing NSString)

kABNoteProperty

Notes. (NSString)

kABMiddleNameProperty

Middle name. This property isn’t displayed in the Address Book application. (NSString)

kABMiddleNamePhoneticProperty

Phonetic representation of the middle name. This property isn’t displayed in the Address Book application. (NSString)

kABTitleProperty

Title, such as “Mr.,” “Mrs.,” “General,” “Cardinal,” or “Lord.” This property isn’t displayed in the Address Book application. (NSString)

kABSuffixProperty

Suffix, such as “Sr.,” “Jr.,” “III.,” or “Esq.” This property isn’t displayed in the Address Book application. (NSString)

kABNicknameProperty

Nickname. This property isn’t displayed in the Address Book application. (NSString)

kABMaidenNameProperty

Maiden name. This property isn’t displayed in the Address Book application. (NSString)

kABOtherDatesProperty

Dates associated with a person (ABMultiDateProperty containing dates).

kABRelatedNamesProperty

Names of people related to a person (ABMultiStringProperty containing names).

kABDepartmentProperty

Department name.

kABPersonFlags

Property that specifies the name ordering and configuration of a record in the Address Book application.

The ABPersonFlags property is used to access the following settings:

Constant

Description

kABShowAsPerson

Record is displayed as a person.

kABShowAsCompany

Record is displayed as a company.

kABShowAsMask

Used in conjuction with kABShowAsPerson and kABShowAsCompany to determine record configuration.

kABDefaultNameOrdering

Default name ordering (whether a person’s first name or last name is displayed first) the Address Book application.

kABFirstNameFirst

First name is displayed first in Address Book.

kABLastNameFirst

Last name is displayed first. in Address Book.

kABNameOrderingMask

Used in conjunction with kABDefaultNameOrdering, kABFirstNameFirst, and kABLastNameFirst to determine name ordering.

These are the default labels contained in the Address Book database for specifying different values in a multi-value list. Users can also add their own labels.

Constant

Description

kABEmailWorkLabel

Home email

kABEmailHomeLabel

Work email

kABAddressHomeLabel

Home address

kABAddressWorkLabel

Work address

kABPhoneWorkLabel

Work phone number

kABPhoneHomeLabel

Home phone number

kABPhoneMobileLabel

Cell phone number

kABPhoneMainLabel

Main phone number

kABPhoneHomeFAXLabel

Home FAX number

kABPhoneWorkFAXLabel

Work FAX number

kABPhonePagerLabel

Pager number

kABHomePageLabel

Web page URL

kABAIMWorkLabel

Work AOL instant messaging ID

kABAIMHomeLabel

Home AOL instant messaging ID

kABJabberWorkLabel

Work Jabber instant messaging ID

kABJabberHomeLabel

Home Jabber instant messaging ID

kABMSNWorkLabel

Work MSN instant messaging ID

kABMSNHomeLabel

Home MSN instant messaging ID

kABYahooWorkLabel

Work Yahoo instant messaging ID

kABYahooHomeLabel

Home Yahoo instant messaging ID

kABICQWorkLabel

Work ICQ instant messaging ID

kABICQHomeLabel

Home ICQ instant messaging ID

kABAnniversaryLabel

Anniversary date

kABMotherLabel

Mother

kABFatherLabel

Father

kABParentLabel

Parent

kABSisterLabel

Sister

kABBrotherLabel

Brother

kABChildLabel

Child

kABFriendLabel

Friend

kABSpouseLabel

Spouse

kABPartnerLabel

Partner

kABAssistantLabel

Assistant

kABManagerLabel

Manager

Use these labels in searches to match all work, home, or other labels. For example, kABWorkLabel can be used in place of kABEmailWorkLabel or kABAddressWorkLabel.

Constant

Description

kABWorkLabel

All Work labels match this label

kABHomeLabel

All Home labels match this label

kABOtherLabel

All labels other than Home or Work labels match this label.

These are the keys contained in each address dictionary. Neither developers nor users can add more keys.

Constant

Description

kABAddressStreetKey

Street

kABAddressCityKey

City

kABAddressStateKey

State

kABAddressZIPKey

Zip

kABAddressCountryKey

Country

kABAddressCountryCodeKey

Country Code

The kABAddressCountryCodeKey must be one of the following ISO country codes.

Country Codes

Description

ae

United Arab Emirates

ar

Argentina

at

Austria

au

Australia

ba

Bosnia and Herzegovina

be

Belgium

bh

Bahrain

br

Brazil

ca

Canada

ch

Switzerland

cn

China

cz

Czech Republic

de

Germany

dk

Denmark

eg

Egypt

es

Spain

fi

Finland

fr

France

gl

Greenland

gr

Greece

hk

Hong Kong

hr

Croatia

hu

Hungary

ie

Ireland

il

Israel

id

Indonesia

in

India

is

Iceland

it

Italy

jp

Japan

jo

Jordan

kr

South Korea

kw

Kuwait

lb

Lebanon

lu

Luxembourg

mk

Macedonia

mx

Mexico

nl

Netherlands

no

Norway

nz

New Zealand

om

Oman

pl

Poland

pt

Portugal

qa

Qatar

ro

Romania

ru

Russian Federation

sa

Saudi Arabia

se

Sweden

sg

Singapore

si

Slovenia

sk

Slovakia

sy

Syrian Arab Republic

tr

Turkey

tw

Taiwan

ua

Ukraine

gb

United Kingdom

us

United States

ye

Yemen

yu

Serbia and Montenegro

za

South Africa



Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-07-07)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.