5

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>
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
marcgg
  • 65,020
  • 52
  • 178
  • 231

3 Answers3

16

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
  • 33,113
  • 21
  • 131
  • 183
4

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
  • 286,113
  • 34
  • 456
  • 610
1

In iOS 9 the ABFramework has been deprecated for the new Contacts Framework:

I show you an example to log every email address of a CNContact:

CNContact * yourContact = //...

for (CNLabeledValue* emailLabeledValue in yourContact.emailAddresses){
    NSLog(@"%@",[emailLabeledValue value]);
}
andreacipriani
  • 2,519
  • 26
  • 23