문제

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;
     }
}
도움이 되었습니까?

해결책

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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top