10

Issue:

When choosing a document from iCloud the application randomly crashes, for most of the time the following code will work, but on rare occasions it will fail.

I have enabled iCloud entitlement in the app and can't seem to find the reason why it intermittently fails. Is there a check that I'm missing?

It's also hanging for a noticeable 5 or so seconds on occasions (usually in the run up to crashing)

Code:

#pragma mark - iCloud =======================================================================================================
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {

BOOL fileUrlAuthozied = [url startAccessingSecurityScopedResource];
NSURL *ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSLog(@"ubiquityURL - %@",ubiquityURL);

if(fileUrlAuthozied){
    NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
    NSError *error;

    [fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {

        NSData *data = [NSData dataWithContentsOfURL:newURL];
        //Do something with data
        selectedDocumentToUpload = [[UploadDocumentObj alloc] initWithiCloudDocument:data];
        [self performSegueWithIdentifier:@"goToRename" sender:nil];

    }];
    [url stopAccessingSecurityScopedResource];
}else{
     //Error handling
    [Lib showErrorMessageWithTitle:@"Alert" message:@"E-Sign could not retrive the document!\nPlease try again." delegate:self];

}
}

Error:

2015-03-18 16:22:15.955 E-Sign[6338:1860982] *** Assertion failure in -[UIDocumentPickerViewController _commonInitWithCompletion:], /SourceCache/UIKit/UIKit-3318.93/UIDocumentPickerViewController.m:66
2015-03-18 16:22:15.960 E-Sign[6338:1860982] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

Other errors:

2015-03-18 16:33:45.884 E-Sign[6357:1864309] plugin com.apple.UIKit.fileprovider.default interrupted
2015-03-18 16:33:45.885 E-Sign[6357:1864309] plugin com.apple.UIKit.fileprovider.default invalidated

Anyone come across this before?

AJ9
  • 1,256
  • 1
  • 17
  • 28
  • Happens to me as well, I'm not sure whether this is a development-only issue, or does it happen on production as well – Nir Golan Apr 16 '15 at 09:15
  • It happens in both. External testers keep reporting the same issue, in the end I removed the whole iCloud functionality due to its unreliability – AJ9 Apr 17 '15 at 10:06

4 Answers4

10

I recently stumpled opon the same problem:

*** Assertion failure in -[UIDocumentPickerViewController _commonInitWithCompletion:]

is caused due to lacking App-Capabilities. Go to your Build and choose Capabilities -> iCloud

Activate it via the switch on the right hand side and toggle iCloud Documents and CloudKit ON. (Notice: This will only work with a payed developer account)

Rebuild->Run

Also have in mind:

iCloud entitlements are available only to apps submitted to the App Store or to the Mac App Store. (Source)

gutenmorgenuhu
  • 2,312
  • 1
  • 19
  • 33
  • 2
    Got the same issue using the `UIDocumentPickerViewController`. On iOS 9/10 the app needs iCloud capabilities. From iOS it isn't necessary anymore... – heyfrank Sep 12 '18 at 09:30
0

Seems the following error is occurring for iCloud entitlement is not being set correctly. Please check it again. Your containing app and extensions needs to be in same App groups. Enable App groups from Capabilities if it is not enabled. If both are are set correctly and still you get the error then have no clue from where it might happen.

2015-03-18 16:22:15.960 E-Sign[6338:1860982] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application initializing document picker is missing the iCloud entitlement. Is com.apple.developer.icloud-container-identifiers set?'

I am also facing other errors. That is why I am here.

eNipu
  • 25
  • 1
  • 8
  • As discussed in the original question, the iCloud entitlement has been enabled. The intermittent nature of the error is the issue. – AJ9 Jun 03 '15 at 08:01
0

After researching a lot I came to an important conclusion :

I was dealing with same kind of issue and it was really hurting. So after checking the code deep and debugging the ultimate result for this is to manage the UI changes which you are performing while displaying the Picker. The transition of displaying the picker and the UI changes generates the irritate behaviour and ultimately crashes and hangs.

So my suggestion would be minimize the UI updation and make those changes in background so that the opening of picker is seamless.

My issue was solved after making those changes.

Ashish
  • 1,978
  • 1
  • 15
  • 7
-1

When calling the method, make sure you call it in background thread. It will fix the problem.

dispatch_async(dispatch_get_global_queuue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ // CALL YOUR METHOD });

Raja Reddy
  • 57
  • 1