【问题标题】:Unable to pick pages file with UIDocumentPickerViewController无法使用 UIDocumentPickerViewController 选择页面文件
【发布时间】:2019-10-12 18:32:19
【问题描述】:

我正在使用 UIDocumentPickerViewController 来挑选文档。以下是指定的尿路感染:

NSArray *types = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeSpreadsheet,(NSString*)kUTTypePresentation,(NSString*)kUTTypePDF,(NSString*)kUTTypeRTF,(NSString*)kUTTypePlainText,(NSString*)kUTTypeText];

UIDocumentPickerViewController *dpvc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];

从 pages 应用程序创建的文件(页面文件)显示为灰色,无法选择。但是 WhatsApp 文档选择器允许选择相同的文件。我是否缺少任何必需的尿路感染?

我的应用:

WhatsApp:

更新

com.apple.iwork.pages.sffpages 对我设备上的页面文件有效,但对 icloud 驱动器上的文件无效。呈现文档选择器的完整代码是:

-(IBAction)showDocumentPicker:(id)sender
{
    NSArray *types = @[(NSString*)kUTTypeImage,(NSString*)kUTTypeSpreadsheet,(NSString*)kUTTypePresentation,(NSString*)kUTTypePDF,(NSString*)kUTTypeRTF,(NSString*)kUTTypePlainText,(NSString*)kUTTypeText, @"com.apple.iwork.pages.sffpages"];

    UIDocumentPickerViewController *dpvc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];

    dpvc.delegate = self;

    //colorFromHex 4285f4
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:66.0/255.0 green:133.0/255.0 blue:244.0/255.0 alpha:1.0]];

    [self presentViewController:dpvc animated:YES completion:nil];
}

【问题讨论】:

  • 据我了解,您需要所有复合内容格式,这些都是 kUTTypePDF、kUTTypeRTFD、kUTTypeFlatRTFD、kUTTypeTXNTextAndMultimediaData、kUTTypeWebArchive。
  • @m1sh0 谢谢,但这些都不起作用:(
  • 你试过这些“com.apple.iwork.pages.pages”、“com.apple.iwork.numbers.numbers”、“com.apple.iwork.keynote.key”吗? ??
  • @m1sh0 是的,试过之后发了一个问题。
  • @m1sh0 在指定这些 UTI 后,我必须清理构建。感谢您的宝贵时间。

标签: ios objective-c file uidocumentpickerviewcontroller


【解决方案1】:

实际上,Pages 文件有 2 种不同类型,可以是捆绑文件或单个文件,我认为您希望您的应用同时处理这两种文件。

对应的UTI是com.apple.iwork.pages.sffpagescom.apple.iwork.pages.pages

导入 iWork 文件的代码示例:

NSArray *types = @[@"com.apple.iwork.pages.sffpages", @"com.apple.iwork.pages.pages", @"com.apple.iwork.numbers.numbers", @"com.apple.iwork.keynote.key"];

UIDocumentPickerViewController *dpvc = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:types inMode:UIDocumentPickerModeImport];

如果您对UIDocumentPickerViewController 仍有疑问,我还建议您观看此 WWDC 会议:https://developer.apple.com/videos/play/wwdc2018/216

【讨论】:

  • com.apple.iwork.pages.sffpages 成功了,但现在页面在我的设备上只能访问。当相同的页面文件复制到 icloud 驱动器 时,它无法访问。
  • 但是 icloud 驱动器上的数字和主题文件可以访问,页面不能访问。
  • 请查看我在问题中的更新。 @TheFlow
  • @iAkki 我用示例代码更新了我的答案,你能试试吗?
  • 已修复!我不知道为什么它总是要求我在更改类型后清理项目。我上次在指定 .sffpages 和 .pages UTI 时忘记清理了。现在它的工作。非常感谢您的帮助:) @TheFlow
猜你喜欢
  • 1970-01-01
  • 2018-12-31
  • 2015-07-30
  • 2021-09-25
  • 1970-01-01
  • 2020-04-15
  • 1970-01-01
  • 1970-01-01
  • 2021-07-01
相关资源
最近更新 更多