How to access the phone contact list and display it in tableview?

江枫思渺然 提交于 2020-02-25 05:48:09

问题


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

Can any one help me how can i achieve this??

Thanx in Advance.


回答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

Hope this help you



来源:https://stackoverflow.com/questions/10174889/how-to-access-the-phone-contact-list-and-display-it-in-tableview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!