ios - 无法使用 UIDocumentPickerViewController 选择页面文件

标签 ios objective-c file uidocumentpickerviewcontroller

我正在使用 UIDocumentPickerViewController 来选取文档。以下是指定的 UTI:

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 app创建的文件(pages file)是灰色的,无法拾取。但是 WhatsApp 文档选择器允许选择相同的文件。我是否缺少任何必需的 UTI?

我的应用:

enter image description here

WhatsApp:

enter image description here

更新

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];
}

最佳答案

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

对应的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 session :https://developer.apple.com/videos/play/wwdc2018/216

关于ios - 无法使用 UIDocumentPickerViewController 选择页面文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56321712/

相关文章:

iOS UITableView : what's the different between "cellForRowAtIndexPath" and "willDisplayCell: forRowAtIndexPath:"

iphone - 这是什么样的数据类型?

iphone - 如何在以编程方式创建的 UILabel 上添加 padding-left?

java - 我如何在 Java 中更新文件,我应该使用哪个类?

php - 使用 PHP 创建一个新目录,并在该目录中创建一个文件

ios - 如何模块化监听通知的类?

ios - 在 Swift、iOS 中通过委托(delegate)在类之间共享数据

iphone - 在 IOS 5 中获取 Facebook 好友列表

ios - Objective-c 清除缓存 NSCachedURLResponse

iphone - 如何从磁盘读取图像并阻塞直到读取?