How to get an iPhone address book contact's emails as NSStrings?

marcgg picture marcgg · Oct 29, 2009 · Viewed 7.8k times · Source

I know that there can be multiple values for an email, but I'm not sure how to browse through them.

I can get a person correctly.

ABRecordRef person = // getting a person;
NSString* emails = (NSString *)ABRecordCopyValue(person, kABPersonEmailProperty);

... what's next? If I try to print the emails variable I get:

Emails: <NSCFType: 0x4018d40>

Answer

coneybeare picture coneybeare · Oct 29, 2009

It is because emails should not be a string, but an array. People can have many emails!

ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty);
CFStringRef email = ABMultiValueCopyValueAtIndex(emails, <INDEX>);
NSLog( (NSString *) email);

Here are some docs on things you can do with MultiValueLists