views:

15

answers:

1

Using the 'AddressBook.framework' is it possible to filter out all companies (i.e. just people). For example, how would one modify the following code to remove companies:

ABAddressBookRef addressbook = ABAddressBookCreate();
CFArrayRef contacts = ABAddressBookCopyArrayOfAllPeople(addressbook);

I found that companies do not appear to be stored as groups (they are still returned with the above call). Thanks!

+1  A: 

You are correct, companies are records/people in the Address Book.

Look up the value for the kABPersonFlags -- one of the flags is "show as company". Then just do a bitmask and compare.

if (([aPerson valueForProperty:kABPersonFlags] & kABShowAsMask) == kABShowAsCompany) {
   // it's a company
} else {
   // it's a person, resource, or room
}

I used the following references from Apple, which you should probably read as well:


EDIT: Sorry, the above is for Address Book on Mac OS X. Try this for iOS:

ABRecordRef aRecord = ...  // Assume this exists
CFNumberRef recordType = ABRecordCopyValue(aRecord, kABPersonKindProperty);
if (recordType == kABPersonKindOrganization) {
   // it's a company
} else {
   // it's a person, resource, or room
}

The idea is the same: get the value of the person type property, and see what it tells you.

Used these Apple docs:

Alex Martini
Awesome! Thanks Alex this is exactly what I am looking for!
Kevin Sylvestre