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.2. Retrieving All the People in the Address Book

10.2. Retrieving All the People in the Address Book

Problem

You want to retrieve all the contacts in the user’s address book.

Solution

Use the ABAddressBookCopyArrayOfAllPeople function to retrieve an array of all contacts:

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

  ABAddressBookRef addressBook = ABAddressBookCreate();

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

    NSArray *arrayOfAllPeople = (__bridge_transfer NSArray *)
                                ABAddressBookCopyArrayOfAllPeople(addressBook);

    NSUInteger peopleCounter = 0;
    for (peopleCounter = 0;
         peopleCounter < [arrayOfAllPeople count];
         peopleCounter++){

      ABRecordRef thisPerson =
        (__bridge ABRecordRef)[arrayOfAllPeople objectAtIndex:peopleCounter];

      NSLog(@"%@", thisPerson);

      /* Use the [thisPerson] address book record */

   ....

  

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