I have an app to store user created contents with a custom file (with a custom extention/UTI), and wanted it to support iCloud Drive using UIDocumentPicker.
1. The problem is, once the file is imported, it is grayed out and becomes unable to import. After trying several things, I found out that the problem is with the custum UTI. If I just changed the file extension to a well-known one, like pdf, it just works.
I also used the sample code below (that just picks a document, and does nothing) to test. If I pick a file with a custom extension, it will be grayed out after being imported once. No problem with pdf files - I could import them again and again.
Am I missing something?
2. Another problem is that, if I specify the document types as @"public.composite-content", I can pick a pdf document in the root but can't access the folders that contain pdf files. If I use kUTTypePDF, I can do both. Is this an expected behavior, or just a bug?
-(void)openDocumentPicker
{
UIDocumentPickerViewController *vc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.composite-content"] inMode:UIDocumentPickerModeImport];
vc.delegate = self;
vc.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:vc animated:YES completion:nil];
}
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
return;
}
In case you still have this problem, or someone else faces the same, this is how I got it to work:
1) UTI declarations in info.plst:
<key>UTExportedTypeDeclarations</key>
<array>
<dict>
<key>UTTypeConformsTo</key>
<array>
<string>public.data</string>
</array>
<key>UTTypeDescription</key>
<string>Holiday backup file</string>
<key>UTTypeIdentifier</key>
<string>de.myDomain.foobar.alb</string>
<key>UTTypeTagSpecification</key>
<dict>
<key>public.filename-extension</key>
<array>
<string>alb</string>
</array>
<key>public.mime-type</key>
<string>application/alb</string>
</dict>
</dict>
</array>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>Holiday backup file</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Owner</string>
<key>LSItemContentTypes</key>
<array>
<string>de.myDomain.foobar.alb</string>
</array>
</dict>
</array>
The UTTypeConformsTo / public.data is the important part here.
2) UIDocumentPicker
UIDocumentPickerViewController* dvc= [[UIDocumentPickerViewController alloc] initWithDocumentTypes:[NSArray arrayWithObject:@"de.myDomain.foobar.alb"] inMode:UIDocumentPickerModeImport];
So in your example above you initialized the picker with @"public.composite-content", while you should use the correct identifier you provided in the info.pls file (in my example "de.myDomain.foobar.alb").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With