Skip to content

Instantly share code, notes, and snippets.

@jquave
Created March 31, 2013 07:44
Show Gist options
  • Save jquave/5279904 to your computer and use it in GitHub Desktop.
Save jquave/5279904 to your computer and use it in GitHub Desktop.
NSMutableArray *abEmailAddresses = [NSMutableArray array];
NSMutableArray *abPhoneNumbers = [NSMutableArray array];
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for (CFIndex i = 0; i < CFArrayGetCount(people); ++i) {
ABRecordRef aRecord = CFArrayGetValueAtIndex(people, i);
// phone numbers
ABMutableMultiValueRef phones = ABRecordCopyValue(aRecord, kABPersonPhoneProperty);
for (CFIndex j = 0; j < ABMultiValueGetCount(phones); j++) {
CFStringRef phoneNumber = ABMultiValueCopyValueAtIndex(phones, j);
[abPhoneNumbers addObject:[NSString stringWithFormat:@"%@", phoneNumber]];
CFRelease(phoneNumber);
}
CFRelease(phones);
// emails
ABMutableMultiValueRef emails = ABRecordCopyValue(aRecord, kABPersonEmailProperty);
for (CFIndex j = 0; j < ABMultiValueGetCount(emails); j++) {
CFStringRef emailAddress = ABMultiValueCopyValueAtIndex(emails, j);
[abEmailAddresses addObject:[NSString stringWithFormat:@"%@", emailAddress]];
CFRelease(emailAddress);
}
CFRelease(emails);
}
CFRelease(people);
CFRelease(addressBook);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment