APAddressBook
APAddressBook copied to clipboard
[APContact initWithRecordRef:fieldMask:] fails when asked to retrieve non-existent fields
If
- you have an initiated ABRecordRef (such as that returned by ABPeoplePickerNavigationController),
- and you try to generate an APContact instance from the ABRecordRef by using [[APContact alloc] initWithRecordRef:recordRef fieldMask:fieldMask],
- and the fieldMask requests an array-type field (such as APContactFieldPhones) that is null / does not exist in the ABRecordRef,
then the program fails.
I believe the APContact should simply set the non-existent fields to a type of null value, if the field does not exist in the ABRecordRef.
I think I may have found the solution.
In APContact.m, line 210, a call to CFRelease(multiValue) is called. It is called whether or not multiValue is not null.
I added a new line under line 202:
if (multiValue == NULL) return;
This has fixed the problem for me. I recommend adding NULL checks throughout the rest of the file as well.