9.2 does not document Contacts.framework requirements for CNKeyDescriptor arrays

Originator:joshavant
Number:rdar://23889946 Date Originated:14-Dec-2015 03:04 PM
Status:Open Resolved:
Product:iOS SDK Product Version:iOS 9.2
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
In 9.0 and 9.1, I used the following line to assemble a CNKeyDescriptor array to pass to CNContactFetchRequest(keysToFetch:):
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactEmailAddressesKey]

In 9.2, I need to use this line, instead:
let keysToFetch = [CNContactPhoneNumbersKey, CNContactEmailAddressesKey, CNContactFormatter.descriptorForRequiredKeysForStyle(.FullName)]

...otherwise, if I try to use CNContactFormatter.stringFromContact() with a contact I receive from that fetch request, I'll encounter an exception that looks something like the following stacktrace:

CrowdRise[94077:15843170] *** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
*** First throw call stack:
(
  0   CoreFoundation                      0x00000001092dbe65 __exceptionPreprocess + 165
  1   libobjc.A.dylib                     0x000000010899adeb objc_exception_throw + 48
  2   CoreFoundation                      0x00000001092dbd9d +[NSException raise:format:] + 205
  3   Contacts                            0x0000000109098c15 -[CNContact middleName] + 160
  4   Contacts                            0x00000001090bc5c6 +[CN(CNInternationalSupport) joinNonEmptyContactProperties:onContact:withDelimiter:] + 291
  5   Contacts                            0x00000001090bc09d +[CN(CNInternationalSupport) localizedNameDelimiterForContact:] + 63
  6   Contacts                            0x0000000109084b77 -[CNContactFormatter fullNameForContact:attributes:style:] + 82

This is important, because I did not notice any documentation about this behavior change in the 9.2 Release Notes.

Also, it seems like the only actual documentation for the method CNContactFormatter.descriptorForRequiredKeysForStyle() is in this high-level documentation for Contacts.framework:
https://developer.apple.com/library/watchos/documentation/Contacts/Reference/Contacts_Framework/index.html

Notably, there's no documentation for descriptorForRequiredKeysForStyle() on its parent class, CNContactFormatter:
https://developer.apple.com/library/watchos/documentation/Contacts/Reference/CNContactFormatter_Class/index.html#//apple_ref/occ/cl/CNContactFormatter

Please improve this documentation. It may also be worth noting in the 9.2 Release Notes about this change in behavior.

Steps to Reproduce:
1. Use the following line to assemble a CNKeyDescriptor array to pass to CNContactFetchRequest(keysToFetch:):
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactEmailAddressesKey]
2. Pass keysToFetch to CNContactFetchRequest(keysToFetch:):.
3. Try to use a CNContact from that fetch request with CNContactFormatter.stringFromContact().

Expected Results:
A formatted contact string is received

Actual Results:
Exception crash with the following stacktrace:

CrowdRise[94077:15843170] *** Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'
*** First throw call stack:
(
  0   CoreFoundation                      0x00000001092dbe65 __exceptionPreprocess + 165
  1   libobjc.A.dylib                     0x000000010899adeb objc_exception_throw + 48
  2   CoreFoundation                      0x00000001092dbd9d +[NSException raise:format:] + 205
  3   Contacts                            0x0000000109098c15 -[CNContact middleName] + 160
  4   Contacts                            0x00000001090bc5c6 +[CN(CNInternationalSupport) joinNonEmptyContactProperties:onContact:withDelimiter:] + 291
  5   Contacts                            0x00000001090bc09d +[CN(CNInternationalSupport) localizedNameDelimiterForContact:] + 63
  6   Contacts                            0x0000000109084b77 -[CNContactFormatter fullNameForContact:attributes:style:] + 82

Version:
iOS 9.2

Notes:


Configuration:
iPhone 6S

Attachments:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!