1

I suppose this is largely a question about how iOS handles deprecating APIs.

I have an app that supports iOS 8.3+, and it worked fine through 9.3.x, but it breaks on iOS 10. When my app lets the user pick a contact, the error that I get is:

Terminating app due to uncaught exception 'CNPropertyNotFetchedException', reason: 'A property was not requested when contact was fetched.'

I found another post here which says that ABAddressBook APIs are deprecated and that I should use CNContactPickerViewController (and related ContactsUI classes) instead. I understand the answer that moving away from deprecated classes and to new & improved classes is the recommended solution. But why do I have to?

I thought that deprecated classes and methods are usually still supported in later versions. It makes no sense to me that my app would work fine on iOS 9.3 and then crash on 10.0, especially given that it compiles just fine (the deployment target is "8.3" and the base SDK is "Latest (10.0)".) Furthermore, some code still works (`ABAddressBookCreateWithOptions').

Finally, is there a good way to analyze the code and highlight all such use of deprecated APIs? My build output doesn't show any such warnings.

Community
  • 1
  • 1
Kenster999
  • 466
  • 2
  • 13

1 Answers1

5

I recently dealt with this myself. The problem has to do with permissions.

Make sure you call ABAddressBookGetAuthorizationStatus() and if the result is kABAuthorizationStatusNotDetermined then you must call ABAddressBookRequestAccessWithCompletion and make use of the completion handler. Only use other address book APIs (including the people picker) after your app has been granted permission.

Attempts to use ABPeoplePickerNavigationController to allow a user to select a contact's property without first ensuring your app has permission to access the address book will result in the error posted in your question.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    I can confirm that ABAddressBook APIs work find on iOS 10 as long as you follow the guidelines posted above, which you should be using for iOS 9+. – Marcus Adams Oct 02 '16 at 00:43
  • That worked for me, thanks! I guess it worked OK without permissions on iOS 8 and iOS 9, but now iOS 10 enforces the need for user permissions. I also discovered that after prompting the user, there is now a "Contacts " slider in my app's Settings page (which makes sense) But toggling the slider sends a SIGKILL (9) signal to the app, causing it to immediately close. But this isn't too much a problem, since when the user switches back to my app it comes back where it left off due to state restoration. Anyway, thanks again for the solution! – Kenster999 Oct 03 '16 at 20:00
  • Yes, it's a new need for iOS 10. Please don't forget to accept answers that solve your issue. – rmaddy Oct 03 '16 at 20:02