1. Address Book Framework

    Plenty of iOS apps are, somehow, a portal to a social world, and hence, they can benefit from the Address Book framework. And we are going to talk a little about this framework today.

    Address Book Framework is, actually, the foundation of the Address Book app, either on the Mac or the phone. It is a C framework written with Core Foundation, and as most of the other core frameworks, there are Cocoa versions. On top of this framework, we found the Address Book UI Framework, a collection of UI widgets provided for the iOS apps to use freely.

    The key object of the framework is the Address Book, where we can find the Source, which group together groups or persons.

    Address Book

    The Address Book is the point of entrance to the list of people in iOS. One of the major responsibilities of this object is to abstract the underlying database. The ABAddressBookRef type has functions that allow the creation of references to the database, save, edit and delete changes, etc. There is also a toll-free bridged Cocoa implementation of the C opaque type, called ABAddressBook.

    The system keeps a shared address book, that is accessible thought the class method

    + sharedAddressBook
    

    And there is also a class method to get a new instance of ABAddressBook,

    + addressBook
    

    The later being more appropriate to use in tight loops to instantiate persons, or whenever a complete new instance is needed.

    Sources

    The Source is new to iOS 4, this object is helpful to know where each contact comes from, for instance, if the person is listed in the Exchange list or not. in iOS 4 there are a number of different source types available.

    Source Type Description
    Local kABSourceTypeLocal contact list backed on the device itself
    Exchange Server kABSourceTypeExchange contact list backed in an Exchange Server
    Exchange Global Address kABSourceTypeExchangeGAL Global Address List from Exchange
    MobileMe kABSourceTypeMobileMe list backed in the Mobile Me service
    LDAP kABSourceTypeLDAP LDAP server
    CardDAV kABSourceTypeCardDAV CardDAV server (system used by Mac OS X server)
    Searchable CardDAV kABSourceTypeCardDAVSearch Searchable CardDAV server

    There is a one-to-many relationship between the source and the people associated with it. That means that if the source is deleted, all the people inside it is also deleted.

    If there are multiple records for the same person (let’s say, Alice is listed in the corporate Exchange server, but she is also a friend listed in the Local source), Address Boo will link the two records, presenting a unified profile that merge together all the different sources.

    The function ABAddressBookCopyArrayOfAllSources that takes an ABAddressBookRef as parameter returns an array (actually, a CFArrayRef) with all the sources available to the address book.

    Person

    A Person in the Address Book framework realm is the object used to represent either an individual, or an organization (like a company, or University). It is basically a collection of properties that can store a single value (like the name) or more than one value (for instance, a list of phone numbers).

    A person does not necessarily have to be backed in a data base, it can be created just to populate a ABPersonViewController for instance.

    The simpler way to create a person is with the function ABPersonCreate which takes no param, but there is also a ABPersonCreateInSource function useful to create a person in a given source.

    Group

    A Group is a many to many relationship, that ties together a bunch of persons. There is ownership between the person and the group, and each person can be listed in any number of different groups. It is important to note that persons are free to live outside groups.

    Not all source types support groups, more conspicuously, Exchange does not know anything about groups. In Exchange we found folders that are represented by individual sources. The reason for that, is that Exchange does not allow for a single entity to be listed in more than one folder, instead, Exchange copy the persons from one folder to the other.

Notes

  1. volonbolon posted this