【问题标题】:UIDocumentInteractionController not displaying app based on UTIUIDocumentInteractionController 不显示基于 UTI 的应用程序
【发布时间】:2020-05-14 12:36:57
【问题描述】:

我想在 iBooks 应用程序中读取 .epub 文件,因此我使用 UIDocumentInteractionController 在 iBooks 中打开 .epub 文件。一切正常,但我只想在 UIDocumentInteractionController 中显示 iBooks 应用程序而不是其他应用程序,所以我为 iBooks 添加了 UTI但它仍然显示下面的所有应用程序是我的代码。

 var sharingController = UIDocumentInteractionController()
  sharingController.url = url
  sharingController.uti = "com.apple.iBooks"
  sharingController.name = url.lastPathComponent
  sharingController.presentOptionsMenu(from: view.frame, in: view, animated: true)

【问题讨论】:

    标签: ios swift iphone xcode ibooks


    【解决方案1】:

    UTI 不是包标识符,而是内容的统一类型标识符

    试试下面的

    sharingController.uti = "org.idpf.epub-container"
    

    或使用 MobileCoreServices 中的常量

    import MobileCoreServices
    
    ...
    sharingController.uti = kUTTypeElectronicPublication as String
    

    更新: 顺便说一句,上面提供的(和其他)选项不会限制调用的选项对话框(见下文),因为它确定了所有能够快速查看、复制、文件的打开等

    // This is the default method you should call to give your users the option to quick look, open, or copy the document.
    // Presents a menu allowing the user to Quick Look, open, or copy the item specified by URL.
    // This automatically determines the correct application or applications that can open the item at URL.
    // Returns NO if the options menu contained no options and was not opened.
    // Note that you must implement the delegate method documentInteractionControllerViewControllerForPreview: to get the Quick Look menu item.
    open func presentOptionsMenu(from rect: CGRect, in view: UIView, animated: Bool) -> Bool
    

    如果你需要open,只有菜单的内容会更短,只支持epub的读者。

    // Presents a menu allowing the user to open the document in another application.  The menu
    // will contain all applications that can open the item at URL.
    // Returns NO if there are no applications that can open the item at URL.
    open func presentOpenInMenu(from rect: CGRect, in view: UIView, animated: Bool) -> Bool
    

    【讨论】:

    • 感谢您的帮助。我对您的 .uti 都进行了尝试,但仍会在 UIDocumentInteractionController 中显示所有应用程序,而不仅仅是 iBooks。
    • @Rushabh,你会打印并显示传入的url 的示例吗?
    • file:///private/var/mobile/Containers/Data/Application/935F34BD-6A11-4593-B8F0-DFA08B2F6264/tmp/FreadOm.epub
    • 我尝试了 presentOpenInMenu 选项,因此它显示了支持 .epub 文件的应用程序列表,但它们以任何方式仅显示 iBooks 应用程序,然后显示其他应用程序
    猜你喜欢
    • 2022-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多