PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

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

 November 06, 2022     abaddressbook, contacts, iphone, objective-c     No comments   

Issue

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?


Solution

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



Answered By - Sadia
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,207,317

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing