I want my users to fill out an email field by selecting a contact email address from their address books. I donβt want them to scroll through all the contacts whose emails are not installed, so I want to filter out those that have email addresses.
This is the code that I have written so far. I can find out who has an email address and who does not, but I could not tell ABPeoplePickerNavigationController to list only the correct contacts. Itβs impossible to achieve this, I mean, should I implement my own contact selection class using a table view or is there something wrong with this piece of code?
ABAddressBookRef addressBook = ABAddressBookCreate(); NSArray *peopleList = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); NSLog(@"%ld people exist in the addressBook", ABAddressBookGetPersonCount(addressBook)); for (id peopleRecord in peopleList) { ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord, kABPersonEmailProperty); CFIndex numberOfAddresses = ABMultiValueGetCount(mv); if(numberOfAddresses == 0) { CFErrorRef err; ABAddressBookRemoveRecord( addressBook, (ABRecordRef)peopleRecord, &err); } } [peopleList release]; NSLog(@"%ld people have an email", ABAddressBookGetPersonCount(addressBook)); ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init]; NSNumber* emailProp = [NSNumber numberWithInt:kABPersonEmailProperty]; [peoplePicker setAddressBook:addressBook]; peoplePicker.displayedProperties = [NSArray arrayWithObject:emailProp]; [peoplePicker setPeoplePickerDelegate:self]; [self presentModalViewController:peoplePicker animated:YES];
source share