Find a "work" email address for a person in your iPhone’s address book?

Is there a way to find a specific kind of email address for a person from the iPhone address book? I know how to get all the email addresses for a person, and not how to determine which email address it is ("home", "work", etc.) ... and (and this may be preferable), a direct way access to this address without having to repeat them all.

Thanks.

+5
source share
1 answer

Check the kABWorkLabel label with ABMultiValueCopyLabelAtIndex.

, ABRecordRef "person", NSString "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);
+15

All Articles