3

I should retrieve/extract all the available properties of an ABPerson. The official documentation for IOS ABPerson Don't include the MACOS available method [ABPerson properties]

What can i do?

  • 1
    Try searching here on ABPerson - this topic has come up a huge number of times and code to do it is on this site already. – David H Sep 06 '12 at 11:03

2 Answers2

1

You could create an NSArray/NSSet with all the properties found in the ABPerson reference under the Personal Information Properties header.

Then just use a for-in to go through the NSArray like so.

NSArray *allPropertiesForABPerson = [NSArray arrayWithObjects: @"kABPersonFirstNameProperty", @"kABPersonLastNameProperty", /*rest of props here*/, nil];

for (id property in allPropertiesForABPerson) {
  id valueForProperty = ABRecordCopyValue(theRecord, property);
  NSLog(@"Value: %@ for property: %@", valueForProperty, property);
  CFRelease(valueForProperty);
}
Alex
  • 7,432
  • 20
  • 75
  • 118
1

Say you have an ABPerson called myFriend. You can access its first name by:

NSString* firstName = (__bridge_transfer NSString*)ABRecordCopyValue(myFriend, kABPersonFirstNameProperty);

Of course, you can replace kABPersonFirstNameProperty with other property constants to get other properties.

Here are some of them:

kABPersonFirstNameProperty
kABPersonLastNameProperty
kABPersonMiddleNameProperty
kABPersonPrefixProperty
kABPersonSuffixProperty
kABPersonNicknameProperty
kABPersonFirstNamePhoneticProperty
ckABPersonLastNamePhoneticProperty
kABPersonMiddleNamePhoneticProperty
kABPersonOrganizationProperty
kABPersonJobTitleProperty
kABPersonDepartmentProperty
kABPersonEmailProperty
kABPersonBirthdayProperty
kABPersonNoteProperty
kABPersonCreationDateProperty
kABPersonModificationDateProperty

More about ABPerson: https://developer.apple.com/library/ios/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/#//apple_ref/doc/constant_group/Personal_Information_Properties

Tim Chen
  • 1,364
  • 12
  • 14