UIDocumentPickerViewController intermittently crashes due to lack of iCloud entitlement

Originator:konstantinos.tsanaktsidis
Number:rdar://20342063 Date Originated:30/3/2015
Status:Open Resolved:
Product:iOS SDK Product Version:8.2
Classification: Reproducible:Sometimes
 
Summary:
We have an application in the App Store which uses a UIDocumentPickerViewController to allow the user to select files from other apps. We have included the correct entitlements with the app, and 99% of the time, this all works fine.

However, we are getting a large number of reports from the field that the application occasionally crashes when using this feature. The crash has the exception message 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

The entitlement is indeed present, because the application works correctly most of the time.

I have found through experimentation that testing ([NSFileManager defaultManager].ubiquityIdentityToken == nil) is a good proxy for whether or not the app will crash when attempting to use a UIDocumentPickerViewController. Guarding the call to UIDocumentPickerViewController with this check appears to have stopped the actual crashes, but of course the file selection feature does not work.

Are you able to provide any guidance as to how to resolve this issue?

Steps to Reproduce:
Our app encounters difficulty simply by calling [UIDocumentPickerViewController initWIthDocumentTypes:]. I tried to reproduce this issue in a small project but it always succeeded without the crash we are encountering in our production app.

Expected Results:
The document picker should appear and prompt the user to choose a file from iCloud

Actual Results:
The app crashes because the UIDocumentPickerViewController cannot find the iCloud entitlement

Version:
Observed on iOS 8.2 & 8.1.2

Notes:


Configuration:
Observed on a wifi iPad air and an iPad mini 2

Comments

Most likely explanation.

This might be caused by users pirating the app. This can cause an app to have invalid iCloud entitlements, which in turn will make UIDocumentPickerViewController throw an exception.

So not a bug in UIKit, it's doing the right thing.


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!