views:

399

answers:

2

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>
+4  A: 

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

coneybeare
Thanks! Do you know how I can get the size of the "emails" array so I can browse it?
marcgg
i added a link to the docs where you will find the 'count' method
coneybeare
for the count I ended up using this: CFIndex count = ABMultiValueGetCount(emails);
marcgg
+2  A: 

The type of this entry is an ABMultiValue (specifically, the type of this field is a kABMultiStringProperty). See "Using Multivalue Lists" for how to read these. See the Address Book Objective-C Constants Reference for what each property returns.

Also, remember that AB functions are subject to the Create Rule. You are responsible for releasing objects you get from a function with the word "Copy" in it.

Rob Napier