Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

10. Address Book > 10.1. Retrieving a Reference to an Address Book

10.1. Retrieving a Reference to an Address Book

Problem

You would like to work with a user’s contacts. To do this, first you need to get a reference to the user’s address book database. This reference is what you use to retrieve entries, as well as to make and save changes.

Solution

Use the ABAddressBookCreate function in the Address Book framework:

- (BOOL)            application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{

  ABAddressBookRef addressBook = ABAddressBookCreate();

  if (addressBook != nil){
    NSLog(@"Successfully accessed the address book.");

    /* Work with the address book here */

    /* Let's see if we have made any changes to the
     address book or not, before attempting to save it */

    if (ABAddressBookHasUnsavedChanges(addressBook)){
      /* Now decide if you want to save the changes to
       the address book */
      NSLog(@"Changes were found in the address book.");

      BOOL doYouWantToSaveChanges = YES;

      /* We can make a decision to save or revert the
       address book back to how it was b....

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial