Unable to pick pages file with UIDocumentPickerViewController

江枫思渺然 提交于 2019-12-14 03:48:23

问题


I'm using UIDocumentPickerViewController for picking document. Below are the specified UTIs :

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

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

The files created from pages app (pages file) are grayed out and unable to pick. But WhatsApp document picker allowed to pick the same files. Am I missing any required UTI ?

My App :

WhatsApp:

UPDATE

com.apple.iwork.pages.sffpages did the trick for pages files on my device, but not working for the files on icloud drive. The complete code to present document picker is:

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

回答1:


Actually, there are 2 different types for Pages files, it could be a bundle or a single file, and I think that you want your app to handle both.

The corresponding UTIs are com.apple.iwork.pages.sffpages and com.apple.iwork.pages.pages.

Example of code to import iWork files:

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

I also recommand that you watch this WWDC session if you still have trouble with UIDocumentPickerViewController: https://developer.apple.com/videos/play/wwdc2018/216



来源:https://stackoverflow.com/questions/56321712/unable-to-pick-pages-file-with-uidocumentpickerviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!