| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AddressBook.framework |
| Availability | Available in Mac OS X v10.2 and later.
|
| Companion guide | |
| Declared in | ABAddressBook.h ABGlobals.h |
The ABAddressBook class provides a programming interface to the Address Book—a centralized database used by multiple applications to store contact and other personal information about people. The Address Book database also supports the notion of a “group” containing one or more persons. People may belong to multiple groups, and groups may also belong to other groups with some restrictions (for example, no circular references are allowed).
The ABAddressBook class provides methods for accessing, adding, and removing group and person records including the “me” record corresponding to the logged-in user. For example, you use the groups method to get an array of all the group records in the database, or the people method to get all the person records. You use the me method to get the person record corresponding to the logged-in user. You can also add and remove records using the addRecord: and removeRecord: methods.
You can also search for records matching a particular query you specify by creating an ABSearchElement object. You use the searchElementForProperty:label:key:value:comparison: method in the ABPerson and ABGroup class to create an ABSearchElement object for the corresponding record. Then use the recordsMatchingSearchElement: ABAddressBook method, passing the ABSearchElement as the argument, to query the database. See ABSearchElement for more methods that create compound queries.
Your application uses a shared instance of ABAddressBook returned by the sharedAddressBook class method to interact with the database (multiple ABAddressBook instances are not supported). Changes you make to record objects are stored in memory and saved to disk when you invoke the saveAndReturnError: method.
The Address Book posts notifications if any application including yours makes changes to the database. Typically, you observe these notifications to update any dependent view or model objects in your application. Use NSNotificationCenter to register for the ABAddressBook notifications: kABDatabaseChangedNotification and kABDatabaseChangedExternallyNotification. These notifications are not sent until thesharedAddressBook class method has been invoked.
The ABAddressBook class is “toll-free bridged” with its procedural C, opaque type, counterpart. This means that the ABAddressBookRef type is interchangeable in function or method calls with instances of the ABAddressBook class.
Returns a new instance of ABAddressBook.
+ (ABAddressBook *)addressBook
+ sharedAddressBookABAddressBook.h
+ (ABAddressBook *)sharedAddressBook
Returns the unique shared instance of ABAddressBook. This method returns the address book for the logged-in user that is shared by every application. If you call this method more than once or try to create a new address book, you get a pointer to the same shared address book.
+ addressBookABAddressBook.h- (BOOL)addRecord:(ABRecord *)record
Adds an ABPerson or ABGroup record to the Address Book database. If the record argument is nil, this method raises an exception. This method returns YES if the record was added successfully, NO otherwise.
– removeRecord:– initWithVCardRepresentation: (ABPerson)ABAddressBook.h- (NSString *)defaultCountryCode
Returns the default country code for records with unspecified country codes.
ABAddressBook.h- (NSInteger)defaultNameOrdering
Returns the default name ordering defined by the user in the Address Book preferences. The possible values are kABFirstNameFirst and kABLastNameFirst.
ABAddressBook.h- (NSAttributedString *)formattedAddressFromDictionary:(NSDictionary *)address
Returns an attributed string containing the formatted address. The string’s attributes match address dictionary keys, such as kABAddressStreetKey. Each attribute value contains the localized description of the key. (For example, the value of a Canadian kABAddressZIPKey field would be “Postal Code”, while the value of a French one would be “Code Postale”.)
ABAddressBook.h- (NSArray *)groups
Returns an array of all the groups in the Address Book database, or returns an empty array if the database doesn’t contain any groups
ABAddressBook.h- (BOOL)hasUnsavedChanges
Returns YES if there are unsaved changes, NO otherwise. The unsaved changes flag is set automatically whenever changes are made.
ABAddressBook.h- (ABPerson *)me
Returns the ABPerson record that represents the logged-in user, or nil if the user never specified such a record.
ABAddressBook.h- (NSArray *)people
Returns an array of all the people in the Address Book database, or an empty array if the database doesn’t contain any people.
ABAddressBook.h- (NSString *)recordClassFromUniqueId:(NSString *)uniqueId
Returns the class name of the record that matches the given unique ID.
ABAddressBook.h- (ABRecord *)recordForUniqueId:(NSString *)uniqueId
Returns the ABPerson or ABGroup record that matches the given unique ID, or nil if no record has the given ID. If uniqueId is nil, this method raises an exception.
– uniqueId (ABRecord)ABAddressBook.h- (NSArray *)recordsMatchingSearchElement:(ABSearchElement *)search
Returns an array of records that match the given search element, or returns an empty array if no records match the search element. If search is nil, this method raises an exception.
+ searchElementForProperty:label:key:value:comparison: (ABPerson)+ searchElementForProperty:label:key:value:comparison: (ABGroup)+ searchElementForConjunction:children: (ABSearchElement)ABAddressBook.h- (BOOL)removeRecord:(ABRecord *)record
Removes an ABPerson or ABGroup record from the Address Book database. If record is nil, this method raises an exception. This method returns YES if the record was removed successfully, NO otherwise.
ABAddressBook.h- (BOOL)save
Saves all the changes made since the last save. Returns YES if this method is successful or there were no changes, NO otherwise.
ABAddressBook.hSaves all the changes made since the last save.
- (BOOL)saveAndReturnError:(NSError **)error
A pointer to an error object that is set to an NSError instance if an error occurs.
YES if successful or there were no changes; otherwise, NO.
ABAddressBook.h- (void)setMe:(ABPerson *)person
Sets the record that represents the logged-in user. If you don’t want a record to represent the logged-in user, then pass nil as the person argument.
ABAddressBook.h
These notifications are sent when something changes in the Address Book database. These are not sent until thesharedAddressBook class method has been invoked.
Posted when this process has changed the Address Book database. The process id of the sender and the effective user ID are always included in the user-info dictionary; you access them through the keys "kABSenderProcessID" and "kABUserUID", respectively. In addition, depending on the operation performed on the address book, one or more of the following keys may be included: kABInsertedRecords, kABUpdatedRecords, and kABDeletedRecords. The values for each of the keys are the unique IDs of the records that were inserted, updated, or deleted, respectively. If the values for all the keys are nil, everything has changed, such as when the Address Book database is restored from a backup copy.
ABGlobals.h
Posted when a process other than the current one has changed the Address Book database. The process id of the sender and the effective user ID are always included in the user-info dictionary; you access them through the keys "kABSenderProcessID" and "kABUserUID", respectively. In addition, depending on the operation performed on the address book, one or more of the following keys may be included: kABInsertedRecords, kABUpdatedRecords, and kABDeletedRecords. The values for each of the keys are the unique IDs of the records that were inserted, updated, or deleted, respectively. If the values for all the keys are nil, everything has changed, such as when the Address Book database is restored from a backup copy.
ABGlobals.h
Last updated: 2007-07-07