In iOS 6, this code always gives me Nil for the second NSLog, however the first always gives the correct Composite Name. Hence I know I have access to the addressbook, if I change the name in addressbook, the code logs the correct Composite Name. No matter how many emails I put in, the contact ABMultiValueGetCount is always Nil. Why is this?
ABRecordRef person = (__bridge ABRecordRef)[addressBookArray objectAtIndex:x];
NSLog(@"%@ -", ABRecordCopyCompositeName(person));
NSLog(@"%ld -", ABMultiValueGetCount(ABRecordCopyValue(person, kABPersonEmailProperty)));
Got it ... looks like some sort of managedObjectContext condition I should have anticipated ...
In one View Controller I did this:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
// Prsented info on the user name, but not on the Emails
CFRelease(addressBook);
In the second view controller I passed addressBookArray to try and save on some cycles then did this:
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
// Successfully accessed name properties (suspect they were chached some where ?
// Unsuccsfully accessed email properties (they have never been accessed so no chache and I get Null
CFRelease(addressBook);
The fix ... In the secondviewController repeat:
addressBookArray = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
Bingo problem solved !!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With