IOS Contact Export

by / Friday, 27 September 2013 / Published in Ipad, Iphone

In IOS we can export contact details(such as contact number,email ids etc) programmatically as per our requirements.With the help of  ABAddressBookref we can manage the operation.

The ABAddressBook opaque type (whose instances are known as address books) provides a programming interface to the Address Book—a centralized database used by multiple applications to store personal information about people. The Address Book database also supports the notion of a “group” containing one or more persons. People may belong to multiple groups, and groups may also belong to other groups.

The ABAddressBook opaque type provides functions for creating references to the Address Book database, saving changes, discarding changes, and registering for changes made externally (by other threads or processes) to the database.

In our project first of all we need to drag a UIButton and a UITableView and drag the outlets of them to the .h file of our controller.On clicking the button the contact details will be exported and displayed in the UITableView.

To access the contact information we need to import a couple of frameworks initially from linked framework section.Then  in our .h file of our project we need to import following:

#import <AddressBookUI/AddressBookUI.h>

Now we will take an array to maintain the imported contact details.

In our .m file first of all we need to import following:

#import <AddressBook/AddressBook.h>

Now in the on click function of the button we need to call a method(say contact export).Here is the method below:


ABAddressBookRef addressBook = ABAddressBookCreate();

NSArray *thePeople = (NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);

// Do whatever you need with thePeople...

CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);

// //NSLog(@"nPeople %d",nPeople);

for(int i = contact_count; i < nPeople; i++)


// [dict removeAllObjects];

ABRecordRef ref = CFArrayGetValueAtIndex(thePeople, i);

CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);

CFStringRef email = ABRecordCopyValue(ref, kABPersonEmailProperty);

NSString *email1 = (NSString*)ABMultiValueCopyValueAtIndex(email, 0);


////NSLog(@"email1 %d",contact_count);


[self.device_contact_array addObject:email1];



[self.contactExportTable reloadData];


The contact details(here emailid ) will be automatically exported and displayed in the UITableView.

for reference click here