Tuesday, June 30, 2015

iOS AddressBook Accessing records - Part I

To use an address book, we need to declare an instance of ABAddressBookRef and set to the value returned from the function ABAddressbookCreate. One can use multiple address book objects, but they are all backed by the same shared database. 

As an important note, instances of ABAddressbookRef cannot be used by multiple threads. Each thread must make its own instance. 

Records
In the address book data base, the information is stored as records. represented by ABRecordRef objects. Each record represents a person group. The function ABRecordGetRecordType returns kABPersonType if the record is a person and kABGroupType if it is a group. Unlike the MacOS record types, here there is no separate classes for different types of records. both person objects and group objects are instances of the same class. 

Record objects cannot be passed across threads safely, instead one should pass the record identifiers. 

Within a record, the data is stored as a collection of properties. The properties available for Group and Person are different, but the function used to access those are the same. The functions ABRecordCopyValue and ABRecordSetValue gets and sets the properties. Properties can also be removed completely. using a function ABRecordRemoveValue. 


Person Records : Person records are made up of both single and multi values properties. Properties that a person can have only one of, such as first name and last name are stored as single value properties. Other properties that a person can have more than one of such as phone number, are multi value properties. 

Group Records. 
Users may organize their contacts into groups for a variety of reasons. For e.g. a user may create a group. Group records have only one property kABGroupNameProperty, which is the name of the group. To get all the members the group, use the function ABGroupCopyArrayOfAllMembers or ABGroupCopyArrayOfAllMembersWithSortOrdering which return a CFArrayRef of ABRecordRef objects.  

References:

No comments:

Post a Comment