I came across a situation where ABAddressBookGetPersonCount returns -1. The tester assures me that there are contacts in the address book. All phones are running iOS 6.0.1.
Here is 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 can not reproduce this on any of my phones, but the tester tried on 3 phones. It works correctly on iPhone 5, but not on 4 or 3;
I can not find any documents indicating what the value -1 means. I suppose this is some kind of mistake, but what?
ios objective-c
TimF Nov 14 '12 at 2:01 2012-11-14 02:01
source share