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 ?
Asked
Active
Viewed 790 times
-3
-
1Read the "Address Book Programming Guide" in the iOS docs. Apple provides classes to select contacts. – rmaddy Sep 12 '15 at 07:23
1 Answers
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
![](../../users/profiles/4238123.webp)
DHEERAJ
- 1,440
- 11
- 32