UIDocumentPickerViewController - all files are grayed out

I am testing the new UIDocumentPickerViewController API in iOS 8. I just want to open the file in iCloud to see how the interaction works.

This is the code that I run from my UIViewController :

 - (IBAction)openDocument:(id)sender { [self showDocumentPickerInMode:UIDocumentPickerModeOpen]; } - (void)showDocumentPickerInMode:(UIDocumentPickerMode)mode { UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[(NSString *)kUTTypeData] inMode:mode]; picker.delegate = self; [self presentViewController:picker animated:YES completion:nil]; } 

openDocument bound to a button in IB. When I click it, it opens the iCloud browser, but each folder in it is grayed out (I created some Keynote, Numbers and Pages files), so I can’t get to the files:

Document Picker with files grayed out .

I checked some docs and did the following (no luck):

  • Enabled iCloud in my application (in the Capabilities section for storing keys and iCloud Documents).
  • Added UTI for public.data in my Info.plist as follows:

     <key>CFBundleDocumentTypes</key> 

    CFBundleTypeIconFile icon.png CFBundleTypeName My Details CFBundleTypeRole viewer LSItemContentTypes public.data LSTypeIsPackage NSDocumentClass Document NSPersistentStoreTypeKey binary

  • Added NSUbiquitousContainerIsDocumentScopePublic key with value YES in my Info.plist.

Any idea what might be wrong or missing?

+6
source share
2 answers

IWork documents do not match kUTTypeData ; they match kUTTypePackage .

However, in iOS 8 beta 3, I had to use exact UTIs:

 UIDocumentPickerViewController *picker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"] inMode:mode]; 
+15
source
 **Swift 3+ Solution** 

It will open and provide access to all elements on the disk.

 //open document picker controller func openImportDocumentPicker() { let documentPicker = UIDocumentPickerViewController(documentTypes: ["public.item"], in: .import) documentPicker.delegate = self documentPicker.modalPresentationStyle = .formSheet self.present(documentPicker, animated: true, completion: { _ in }) } /* * * Handle Incoming File * */ func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { if controller.documentPickerMode == .import { let alertMessage: String = "Successfully imported \(url.absoluteURL)" } } /* * * Cancelled * */ func documentPickerWasCancelled(_ controller: UIDocumentPickerViewController) { print("Cancelled") } 
+7
source

Source: https://habr.com/ru/post/971564/


All Articles