0

I worked with AddressBook framework (iPhone SDK). I displayed my contacts as modal view controller and browsed it. I wonder is it possible to retrieve all contacts data without this modal view controller and human interactions.

P.S. it seems NOT because of Apple policy, but I still need to have a '100% sure' answer

Dmitry Pilipenko
  • 339
  • 6
  • 16

1 Answers1

2

To retrieve an array of all contacts use the ABAddressBookCopyArrayOfAllPeople function as the following :

- (void)viewDidLoad
{
    [super viewDidLoad];
    ABAddressBookRef addressBook = ABAddressBookCreate();
    if (addressBook != nil)
    {
        NSLog(@"Successfully accessed the address book.");
        CFArrayRef arrayOfAllPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
        if (arrayOfAllPeople != nil)
        {
            NSUInteger peopleCounter=0;
            for (peopleCounter=0;peopleCounter<CFArrayGetCount(arrayOfAllPeople); peopleCounter++)
            {
                ABRecordRef thisPerson=CFArrayGetValueAtIndex(arrayOfAllPeople,peopleCounter);
                NSLog(@"%@", thisPerson);
                /* Use the [thisPerson] address book record */
            }
            CFRelease(arrayOfAllPeople);
        }
        /* if (allPeople != nil){ */
        CFRelease(addressBook);
    } /* if (addressBook != nil){ */
}
Rok Jarc
  • 18,765
  • 9
  • 69
  • 124
Lokus001
  • 159
  • 1
  • 5