1

Such as the Table cell having:

  1. Contact image

  2. Contact name.

I found that we have to use framework:

  1. AddressBook.framework

  2. AddressBookUI.framework

How can I achieve this?

Dharman
  • 30,962
  • 25
  • 85
  • 135
RayofHope
  • 1,187
  • 2
  • 14
  • 30

1 Answers1

1
ABAddressBookRef addressBook = ABAddressBookCreate(); // create address book reference object
NSArray *abContactArray = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook); // get address book contact array

NSInteger totalContacts =[abContactArray count];
    
for(NSUInteger loop= 0 ; loop < totalContacts; loop++)
{
    ABRecordRef record = (ABRecordRef)[abContactArray objectAtIndex:loop]; // get address book record
        
   if(ABRecordGetRecordType(record) ==  kABPersonType) // this check execute if it is person group
    {
            ABRecordID recordId = ABRecordGetRecordID(record); // get record id from address book record
            
            NSString *recordIdString = [NSString stringWithFormat:@"%d",recordId]; // get record id string from record id
            
            NSString *firstNameString = (NSString*)ABRecordCopyValue(record,kABPersonFirstNameProperty); // fetch contact first name from address book  
            NSString *lastNameString = (NSString*)ABRecordCopyValue(record,kABPersonLastNameProperty); // fetch contact last name from address book
    }
}

for more check these links

http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html

http://developer.apple.com/library/ios/#DOCUMENTATION/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html

Dharman
  • 30,962
  • 25
  • 85
  • 135
Sadia
  • 462
  • 1
  • 5
  • 13
  • Thanx Sadia :) ... It Works for me but still fighting to display contact image :( – RayofHope Apr 17 '12 at 06:26
  • Yuupppp... i got solution to display contact image also for that i use.... NSData *imageData = [(NSData *)ABPersonCopyImageDataWithFormat(record, kABPersonImageFormatThumbnail) autorelease]; – RayofHope Apr 17 '12 at 07:58
  • Why can I access contacts in iOS6 without being prompted?http://stackoverflow.com/questions/13277249/why-can-i-access-the-iphone-address-book-contacts-without-being-prompted – quantumpotato Nov 07 '12 at 20:11