Kevin Sylvestre
Kevin Sylvestre

Reputation: 38012

Filter Companies from Address Book References

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!

Upvotes: 1

Views: 689

Answers (1)

Alex Martini
Alex Martini

Reputation: 760

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:

Upvotes: 4

Related Questions