Chapter 18. Address Book
The user’s address book, which the user sees through the Contacts app, is effectively a database that your code can access programmatically through the Address Book framework. You’ll need to import AddressBook. This is, unfortunately, an archaic C API without memory management information, so you’re going to be intervening constantly to help manage memory.
A user interface for interacting with the address book is provided by the Address Book UI framework. You’ll need to import AddressBookUI.
Address Book Database
The address book is an ABAddressBook object obtained by calling ABAddressBookCreateWithOptions. There are in fact no options to pass. You’re probably going to need a single persistent reference to the address book, so it is tempting to assign this reference to a property as its default value:
var adbk : ABAddressBook =
ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()However, there’s a serious problem with that approach. Access to the address book database requires user authorization. If the authorization status is .NotDetermined, the preceding code does a very bad thing: it fails silently, yielding a non-nil result and not reporting an error. You thus end up with an ABAddressBook reference that is completely invalid and useless — and you have no way of finding out that this has happened. It is crucial, therefore, to verify authorization status independently, as I shall now describe.
Address Book Authorization
Address book authorization is ...
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