ios - UIDocumentInteractionController可以预览哪些文件类型?

标签 ios objective-c uikit uidocumentinteraction

我正在将UIDocumentInteractionController放入我的应用程序中,该程序可以从服务器下载任意文件类型。

它的存在有两个目的:

  • 允许用户在另一个可能查看该文件的应用程序中“打开”该文件。
  • 预览内置UIDocumentInteractionController能够预览的文件。

  • 我想要这样做的是仅尝试显示系统能够预览的文件类型的预览。例如,如果它是一个zip文件,则系统无法预览该文件,因此我想直接转到“打开位置”。

    我在任何地方都找不到支持预览的类型的列表。

    这是我的代码:
    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;
         }
    }
    

    最佳答案

    方法presentPreviewAnimated:返回一个BOOL值(如果可以预览,则返回YES,如果不进行管理,则返回NO),因此您可以:

    if (![self.docController presentPreviewAnimated:YES])
    {
        //present openIn
    }
    

    关于ios - UIDocumentInteractionController可以预览哪些文件类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948102/

    相关文章:

    ios - 找不到匹配的配置文件 : Your build settings specify a provisioning profile with the UUID “fbbe2..” , 但是,没有这样的

    ios - 在 iOS 中使用 NSDictionary 的可扩展 UITableview 单元格

    JavaScriptCore 可移植性

    ios - UIScrollView 缩放到错误的点

    ios - 无法将类型 'Range<String.Index>?' 的值转换为指定类型 'NSRange'(又名 '_NSRange')

    ios - 如何使用用户的 Twitter 帐户登录应用程序?

    ios - 无法在具有@objc 属性的协议(protocol)中使用自定义类?

    ios - 是否可以让 iPad 显示没有弹出窗口的正常操作表?

    iOS - 内容 View 非常大的 UIScrollView,如何减少内存使用?

    ios - 从 Crashlytics 3.0.0 开始,实现用户提示是应用程序的责任