0

Possible Duplicate:
Programmatically Request Access to Contacts in iOS 6

I'm trying to test out some functionality on my iPhone in which I pull all the address book members and display them in a table. This works fine on the simulator, and I see the mock contacts like "John Appleseed". When I run the code on my iPhone, I only see "Mobile User" which apparently is me.

How do I see all my address book contacts?

Community
  • 1
  • 1
joslinm
  • 7,845
  • 6
  • 49
  • 72

1 Answers1

1

In iOS 6 the user has to give permission to apps to use the contact information.

There are a lot examples of this if you google for it. You could use something like:

ABAddressBookRef addressBook = ABAddressBookCreate();

__block BOOL accessGranted = NO;
if (ABAddressBookRequestAccessWithCompletion != NULL) { // we're on iOS 6
    dispatch_semaphore_t sema = dispatch_semaphore_create(0);
    ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
        accessGranted = granted;
        dispatch_semaphore_signal(sema);
    });
    dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
    dispatch_release(sema);   
}
else { // we're on iOS 5 or older
    accessGranted = YES;
}

if (accessGranted) {
    // Do whatever you want here.
}

Check out this question for more information: Programmatically Request Access to Contacts

Community
  • 1
  • 1
Tieme
  • 62,602
  • 20
  • 102
  • 156