7

I'm using ABPeoplePicker to show a list of contacts.

I'd like to filter this list of contacts to only show the contacts that have email addresses. How would I do so?

smtlaissezfaire
  • 437
  • 2
  • 7
  • 18

4 Answers4

3

I needed it, so I started working on something like that. Check out https://github.com/stuffmc/MCFilteredPeoplePickerNavigationController

StuFF mc
  • 4,137
  • 2
  • 33
  • 32
  • You put a "How to use" but you show nothing about actually filtering. – Fogmeister May 08 '13 at 14:02
  • 1
    It's for the user to filter. But if you look at the code (specifically at `loadContacts` you should find it — check https://github.com/stuffmc/MCFilteredPeoplePickerNavigationController/blob/master/Source/MCFilteredPeoplePickerTableViewController.m#L177 – StuFF mc May 09 '13 at 14:44
  • Ah, I see. I was looking for something where I (as the dev) could filter the list to only show contacts with emails :D – Fogmeister May 09 '13 at 14:52
  • Turns out that's also something I do, if you look [here](https://github.com/stuffmc/MCFilteredPeoplePickerNavigationController/blob/master/Source/MCFilteredPeoplePickerTableViewController.m#L169) you'll see I only take those contacts having a `kABPersonAddressProperty` (an address). – StuFF mc May 10 '13 at 15:51
2

here is the good blog tutorial for extracting address book values,

http://blog.slaunchaman.com/2009/01/21/cocoa-touch-tutorial-extract-address-book-address-values-on-iphone-os/

try with below:

ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
    [peoplePicker setPeoplePickerDelegate:self];
    [peoplePicker setDisplayedProperties:[NSArray arrayWithObject:[NSNumber numberWithInt:kABPersonEmailProperty]]];
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
  • 6
    This code doesn´t answer the question. This displays all the contacts, and when you select it only shows email (or "No email addresses" when the contact is without email). – Olof Mar 13 '12 at 18:48
0

I'm trying to do a similar thing. I've gotten an instance of ABAddressBook, removed the entries I don't want, then set picker.addressBook = filteredBook. It...KINDA works. The list seems to be filtered, but entries are duplicated like it expects the full list to be there and it just copies existing entries until it has the expected count, or something.

Erhannis
  • 4,256
  • 4
  • 34
  • 48
0

ABContactHelper is a greater wrapper for the Addressbook and has some methods for filtering contacts based on various things.

https://github.com/erica/ABContactHelper

Toby Allen
  • 10,997
  • 11
  • 73
  • 124