Cannot set addressBook property of ABPeoplePickerNavigationController without crashing

I want to display ABPeoplePicker only with people who have a specific geographic address.

So, I create an address book and delete people who do not have an address:

addressBook = ABAddressBookCreate();
NSArray *peopleList = (NSArray *)ABAddressBookCopyArrayOfAllPeople( addressBook );
NSLog(@"There are %d people in addressBook", ABAddressBookGetPersonCount(addressBook));
for (id peopleRecord in peopleList) {
  ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord, kABPersonAddressProperty);
  CFIndex numberOfAddresses = ABMultiValueGetCount(mv);
  if( numberOfAddresses == 0 ) {
    CFErrorRef err;
    ABAddressBookRemoveRecord( addressBook, (ABRecordRef)peopleRecord, &err);
  }
}
[peopleList release];
NSLog(@"There are now %d people in addressBook", ABAddressBookGetPersonCount(addressBook));
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
NSNumber* addressProp = [NSNumber numberWithInt:kABPersonAddressProperty];
[peoplePicker setAddressBook:addressBook];
peoplePicker.displayedProperties = [NSArray arrayWithObject:addressProp];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];

      

For information, before filtering I have 125 records and after filtering I have 93 records.

When I show peoplePicker and view it, it crashes with:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (49) beyond bounds (49)'

      

Any idea what's wrong?

0


a source to share


1 answer


The fact that the NSRangeException value is 49 (and not some number between 93 and 125), I initially suspected that it was not directly related to that address book. Add a breakpoint for objc_exception_throw

. This will cause you to jump into the debugger at the point of the exception, allowing you to see who picked it at all.



0


a source







All Articles