Alterplay / APAddressBook

Easy access to iOS address book
MIT License
1.38k stars 192 forks source link

[APContact initWithRecordRef:fieldMask:] fails when asked to retrieve non-existent fields #66

Open austin-bowen-advyon opened 9 years ago

austin-bowen-advyon commented 9 years ago

If

  1. you have an initiated ABRecordRef (such as that returned by ABPeoplePickerNavigationController),
  2. and you try to generate an APContact instance from the ABRecordRef by using [[APContact alloc] initWithRecordRef:recordRef fieldMask:fieldMask],
  3. 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.

austin-bowen-advyon commented 9 years ago

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.