Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this contact always coming up as Nil / null, even when I set it or add emails?

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)));
like image 708
Aardvark Avatar asked Jan 19 '26 06:01

Aardvark


1 Answers

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 !!

like image 142
Aardvark Avatar answered Jan 21 '26 09:01

Aardvark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!