I am running into a situation where ABAddressBookGetPersonCount is returning -1. The tester assures me there contacts do exist in the address book. All the handsets are running iOS 6.0.1.
Here's the code:
NSMutableDictionary *myAddressBook = [[NSMutableDictionary alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
int numEntries = ABAddressBookGetPersonCount(addressBook);
if (numEntries == 0)
{
NSString *title = NSLocalizedString(@"error", nil);
NSString *description = NSLocalizedString(@"error_empty_contacts", nil);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:description
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
return;
}
NSLog(@"emails: found %d", numEntries);
I am not able to reproduce this on any of my handsets, but the tester has tried on 3 handsets. It works properly on an iPhone 5, but not on a 4 or 3;
I can't find any docs that indicate what a value of -1 means. I'm assuming it's an error of some kind, but what?