I suspect your problem is to do with the differences between 64bit and 32bit architecture, Xcode 5.1 has enabled 64bit support by default. If pointers are 64 bits and ints are 32 bits, an int is too small to hold a pointer value.
You can disable 64bit compilation for your App by going to your target > build settings but I would highly recommend you don't do that. Besides, The following code works for me, it also implements the new creation method, and correctly implements the authorisation check (this makes sure the user has granted permission for your App to access the contacts)
CFErrorRef * err;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, err);
ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
if (!granted) {
// No Access to address book, user has denied
return;
}
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFMutableArrayRef peopleMutable = CFArrayCreateMutableCopy(kCFAllocatorDefault,
CFArrayGetCount(people),
people);
CFArraySortValues(peopleMutable,
CFRangeMake(0, CFArrayGetCount(peopleMutable)),
(CFComparatorFunction) ABPersonComparePeopleByName,
(void*) ABPersonGetSortOrdering());
CFRelease(addressBook);
CFRelease(people);
CFRelease(peopleMutable);
});
Although if I wanted to be really picky, i'd say you should probably cast the people
array into an NSArray like this:
NSArray *people = (__bridge_transfer NSArray*)ABAddressBookCopyArrayOfAllPeople(addressBook);
Then consider implementing your sorting methods using NSSortDescriptors
as they are likely to be faster, and certainly a more modern way of doing things.