1

I'm putting a UIDocumentInteractionController into my app, which can download arbitrary file types from a server.

It's there for two purposes:

  1. To allow the user to 'Open In' the file in another app that may be able to view the file.
  2. To preview files that the built-in UIDocumentInteractionController is able to preview.

What I'd like to so is to only attempt to display the preview for file types that the system is able to preview. For example, if it's a zip file, the system can't preview that so I want to go straight to the 'Open In'.

I can't find anywhere a list of the types that are supported for preview.

Here's my code:

self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:path]];
[self.docController setDelegate:self];

// I'd like to skip this line if the system can't preview the file.     

BOOL isOpen = [self.docController presentPreviewAnimated:YES];
if (!isOpen) {
    BOOL canOpen = [self.docController presentOpenInMenuFromRect:CGRectMake(300, 300, 100, 100)
                                                          inView:self.view
                                                        animated:NO];
    if (!canOpen) {
          // tell user to install an app that's able to open this file.
          return;
     }
}
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
Ben Clayton
  • 80,996
  • 26
  • 120
  • 129

1 Answers1

5

The method presentPreviewAnimated: returns a BOOL value (YES if it manages to preview and NO for not managing) so you can:

if (![self.docController presentPreviewAnimated:YES])
{
    //present openIn
}
Refael.S
  • 1,634
  • 1
  • 12
  • 22
  • Thanks for the answer. Unfortunately that method returns 'YES' for a zip file. I suppose the system thinks it *can* preview a ZIP file, as it does shown the filename and filesize. Perhaps this isn't possible? – Ben Clayton Jan 06 '14 at 11:07
  • If only zip file is your problem so add a check if the file for preview is a zip file and then if yes openIn and do not preview – Refael.S Jan 06 '14 at 11:12
  • Thanks for the help. The files can be any type, so I'll just live with the system sometimes showing a preview for things like zip and possibly other. – Ben Clayton Jan 06 '14 at 13:46
  • now UIDocumentInteractionController correctly manages the file with .zip extension. – Alessio Campanelli Sep 14 '16 at 15:20