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; }
source share