如何访问手机联系人列表并在tableview中显示?

时间:2012-04-16 13:16:03

标签: iphone objective-c contacts abaddressbook

表格单元格如下:

  1. 联络图片
  2. 联系人姓名。
  3. 我发现我们必须使用框架:

    1. AddressBook.framework
    2. AddressBookUI.framework
    3. 任何人都可以帮助我如何实现这个目标?

      提前完成。

1 个答案:

答案 0 :(得分: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
    }
}

了解更多信息,请查看这些链接

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

希望这能帮到你