-3

I am doing demo for getting selected single contact into my app. I have seen in github there are so many libraries, but all those are based on the podfile . But I don't want to podfile. So How can I get solution for this ?

rmaddy
  • 298,130
  • 40
  • 468
  • 517
Karthik Mandava
  • 497
  • 1
  • 8
  • 22
  • 1
    Read the "Address Book Programming Guide" in the iOS docs. Apple provides classes to select contacts. – rmaddy Sep 12 '15 at 07:23

1 Answers1

1

Check this code.

CFErrorRef *error = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, error);
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex numberOfPeople = ABAddressBookGetPersonCount(addressBook);

for(int i = 0; i < numberOfPeople; i++) {

    ABRecordRef person = CFArrayGetValueAtIndex( allPeople, i );

    NSString *firstName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty));
    NSString *lastName = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty));
    NSLog(@"Name:%@ %@", firstName, lastName);

    ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);

    for (CFIndex i = 0; i < ABMultiValueGetCount(phoneNumbers); i++) {
        NSString *phoneNumber = (__bridge_transfer NSString *) ABMultiValueCopyValueAtIndex(phoneNumbers, i);
        NSLog(@"Phone:%@", phoneNumber);
    }

}

Make sure u add the address book framework to the project

DHEERAJ
  • 1,440
  • 11
  • 32