Xcode to get contact email from address book

How can I get the contact email address in the iPhone address book? I have an application in which I want to import any contact from the address book with all its information, such as name, number, email address. Name, number is working fine. I also want to get the address. Please help with the code function.

+4
source share
1 answer

You must add the AddressBook.framework frame work and add #import <AddressBook/AddressBook.h> to the .m file.

Get contact email from address book:

 ABAddressBookRef addressBook = ABAddressBookCreate(); CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook); NSMutableArray *allEmails = [[NSMutableArray alloc] initWithCapacity:CFArrayGetCount(people)]; for (CFIndex i = 0; i < CFArrayGetCount(people); i++) { ABRecordRef person = CFArrayGetValueAtIndex(people, i); ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty); for (CFIndex j=0; j < ABMultiValueGetCount(emails); j++) { NSString* email = (NSString*)ABMultiValueCopyValueAtIndex(emails, j); [allEmails addObject:email]; [email release]; } CFRelease(emails); } NSLog(@"All Mails:%@",allEmails); CFRelease(addressBook); CFRelease(people); 

I think it will be useful for you.

Edit ::

You should use the delegate method - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person . When you select any person in the contact list that will call this method. Try it...

 - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { ABMultiValueRef emails = ABRecordCopyValue(person, kABPersonEmailProperty); NSString *emailId = (NSString *)ABMultiValueCopyValueAtIndex(emails, 0);//0 for "Home Email" and 1 for "Work Email". NSLog(@"Email:: %@",emailId); return YES; } 
+5
source

All Articles