My app is getting crashed on UIDocumentPickerViewController

Anand3777 picture Anand3777 · Mar 27, 2015 · Viewed 16.1k times · Source

I am working on file sharing on my iOS App, I am new to UIDocumentPickerViewController. I do not know why my app is crashing.

UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.image"] inMode:UIDocumentPickerModeImport];
documentPicker.delegate = self;
documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:documentPicker animated:YES completion:nil];

App is crashing on the highlighted lines.

Has anyone done this previously? I want to do the same like the attachment below enter image description here

Answer

Francesco Vadicamo picture Francesco Vadicamo · Mar 30, 2015

See Prerequisite section on Apple Documentation:

Before your app can use the document picker, you must turn on the iCloud Documents capabilities in Xcode

enter image description here

Let me know if this solve your problem!