I am trying to filter the entries in the Address Book when it pops up using ABPeoplePickerNavigationController. I don't want to save the filtered list to the system address book, but I want to just use the filtered list temporarily to display / choose in ABPeoplePickerNavigationController. Here is a simplified version of the code that I'm using:
This code seems to run fine, however when showFilteredAddressBook() calls presentModalViewController, I get the following error:
I verified that some of my entries do meet the criteria, and hence some records are being removed. It appears however that somehow an array count inside the ABAddressBook is not getting updated properly.
Has anyone done something similar? Am I missing something? Any help would be greatly appreciated.
Sincerely,
Dave Bredesen
Code:
- (ABAddressBookRef) getFilteredAddressBook {
/// open the default address book.
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
for (int i=0;i < nPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
if (/* some condition */) {
ABAddressBookRemoveRecord(addressBook, ref, nil);
}
}
return addressBook;
}
- (IBAction)showFilteredAddressBook:(id)sender {
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
peoplePicker.addressBook = [self getFilteredAddressBook];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];
}
This code seems to run fine, however when showFilteredAddressBook() calls presentModalViewController, I get the following error:
Code:
-[NSArray subarrayWithRange:]: index (5) beyond bounds (5)'
I verified that some of my entries do meet the criteria, and hence some records are being removed. It appears however that somehow an array count inside the ABAddressBook is not getting updated properly.
Has anyone done something similar? Am I missing something? Any help would be greatly appreciated.
Sincerely,
Dave Bredesen