Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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), a way to directly access that address without having to iterate through them all.

Thanks.

like image 878
Greg Maletic Avatar asked Jan 22 '10 19:01

Greg Maletic


People also ask

Does iPhone have an email address book?

The Contacts app that is built into iOS contains the same information as the Contacts icon inside the Phone app. Any change you make to a contact in either place appears in both locations.

How do I find a friend's iCloud email?

You can search for a contact by name or any other information included on a contact card. In Contacts on iCloud.com, click the group you want to search in the sidebar. If you want to search all contacts, select the All Contacts group.

How do I add my work email to my iPhone calendar?

Go to Settings > Calendar > Accounts > Add Account. Do one of the following: Choose a service: Tap a service—for example, iCloud or Microsoft Exchange—then enter your account information. Add a calendar account: Tap Other, tap Add CalDAV Account, then enter your server and account information.

How does iPhone choose suggested contacts?

Answer: A: Answer: A: The suggested contacts are more than just "recent contacts". The contacts that appear are based on not only who you've contacted recently but also on your location and the time of day.


1 Answers

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);
like image 58
gerry3 Avatar answered Sep 24 '22 14:09

gerry3