user1651591
user1651591

Reputation:

IOS retrieve properties from an ABPerson

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?

Upvotes: 3

Views: 1770

Answers (2)

Tim Chen
Tim Chen

Reputation: 1402

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

Upvotes: 1

Alex
Alex

Reputation: 7622

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);
}

Upvotes: 1

Related Questions