Find a "work" email address for a person in iPhone Address Book?
Is there a way to find a particular kind of email address for a person from the iPhone Address Book? I know how to get all of the email addresses for a person, just not how to identify what kind of e-mail address it is ("home", "work", etc.)...nor (and this might be preferable)开发者_如何学Go, a way to directly access that address without having to iterate through them all.
Thanks.
Check for a label of kABWorkLabel using ABMultiValueCopyLabelAtIndex.
For example, if you have an ABRecordRef named "person", this code will set a single NSString named "emailAddress":
// Email address (if only one, use it; otherwise, use the first work email address)
CFStringRef value, label;
ABMutableMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty);
CFIndex count = ABMultiValueGetCount(multi);
if (count == 1) {
value = ABMultiValueCopyValueAtIndex(multi, 0);
emailAddress = (NSString*)value;
[emailAddress retain];
CFRelease(value);
} else {
for (CFIndex i = 0; i < count; i++) {
label = ABMultiValueCopyLabelAtIndex(multi, i);
value = ABMultiValueCopyValueAtIndex(multi, i);
// check for Work e-mail label
if (label && CFStringCompare(label, kABWorkLabel, 0) == 0) {
emailAddress = (NSString*)value;
[emailAddress retain];
break;
}
CFRelease(label);
CFRelease(value);
}
}
CFRelease(multi);
精彩评论