开发者

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 w开发者_JS百科ould 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!


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:

  • Address Book Programming Guide for Mac OS X
  • Address Book Constants Reference
  • ABPerson Class Reference

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:

  • Address Book Programming Guide for iOS
  • ABPerson Reference
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜