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

十年热恋 提交于 2019-12-03 15:55:05

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

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.

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]);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!