iAkshay
iAkshay

Reputation: 1263

Unable to pick pages file with UIDocumentPickerViewController

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 :

enter image description here

WhatsApp:

enter image description here

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

Upvotes: 4

Views: 654

Answers (1)

Florentin
Florentin

Reputation: 1443

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

Upvotes: 5

Related Questions