3

是否UIDocumentPickerViewController initWithDocumentTypes需要公共 UTI 才能运行?

我正在尝试利用 iCloud Documents 来允许用户从 iCloud Drive 导入专有文件类型。测试适用于公共 UTI,例如:@"public.text"

如果我没有在initWithDocumentTypes数组中包含公共 UTI,我会看到一个屏幕指示:

没有文件。iCloud Drive 中的文档不可用,因为 iCloud Documents & Data 设置被禁用。

我导入的 UTI 在 Target > Info 中定义为“com.domain.file”。我必须相信这是正确设置的,因为我可以在另一个应用程序(例如 Dropbox)中选择我的一个专有文件,并且我的应用程序显示在 Open In... 选项中。

在我的导入操作中,我尝试了所有我能想到的变体来让我的自定义 UTI 显示选择器。

- (IBAction)importDocumentPickerTapped:(id)sender
{
    UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc initWithDocumentTypes:@[@"com.domain.file", @"com.domain.app.file", @"iCloud.com.domain.file", @"iCloud.com.domain.app.file" ] inMode:UIDocumentPickerModeImport];
    documentPicker.delegate = self;
    documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
    [self presentViewController:documentPicker animated:YES completion:nil];
}

如果我添加@"public.text"initWithDocumentTypes阵列中,则 iCloud Drive Locations 选择器屏幕将按预期显示。我可以选择 .txt 和 .rtf 文件,但我的自定义文件类型显示为灰色且不可选择。

笔记:

  1. 我没有创建文档提供程序扩展,因为我不认为这是必需的,而且我的文件格式并不常见。
  2. 当我对 执行任何操作时,我会看到以下警告UIDocumentPickerViewController,即使它是取消并且即使对文件的操作(即保存 .txt)有效。我花了很多时间试图追查这个警告的来源,但无济于事。

插件 com.apple.UIKit.fileprovider.default 无效

4

1 回答 1

2

我遇到了这个问题,并通过让我的自定义导出 UTI 符合“public.data”UTI 来解决它。

您可以通过选择目标然后选择信息选项卡来进行设置。滚动到导出的 UTI 部分并展开它。在您的自定义 UTI 下,有一个框来声明它符合。

有关系统定义的 UTI 列表,请参见此处: https ://developer.apple.com/library/ios/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html

于 2015-05-15T01:36:48.110 回答