【问题标题】:UIDocumentInteractionController does not open other app in iOS 11UIDocumentInteractionController 不会在 iOS 11 中打开其他应用程序
【发布时间】:2017-10-02 18:33:53
【问题描述】:

在 iOS 11 中,我的应用程序无法将 PDF 共享给另一个第三方应用程序。它会显示共享表,但是当我选择在其他(第三方)应用程序中打开它时,它只会关闭共享表并什么都不做。

我已经确认的事情:

  • willBeginSending 和 didEndSending 的委托方法都被调用
  • 打开邮件或便笺等第一方应用可以正常工作
  • 文档选择器仍在内存中
  • 呈现预览效果很好,但预览中的分享按钮仍然无法打开第三方应用
  • 我也尝试过使用UIActivityViewController。共享 URL 会产生相同的行为。共享原始数据可让您“创建 PDF”,然后共享该 PDF 确实有效(但用户体验很糟糕)。

有其他人经历过这种情况或对如何解决它有任何想法吗?

这是显示问题的示例应用程序的完整代码。我在一个新的“单一视图”应用程序中创建了它。故事板只有两个按钮连接到这两个动作。

class ViewController: UIViewController {
    var docController: UIDocumentInteractionController!

    @IBAction func open(sender: UIButton) {
//        self.docController.presentPreview(animated: true)
        self.docController.presentOptionsMenu(from: sender.frame, in:self.view, animated:true)
    }

    @IBAction func check() {
        print(self.docController)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        let url = Bundle.main.url(forResource: "OrderForm", withExtension: "pdf")!
        self.docController = UIDocumentInteractionController(url: url)
        self.docController.delegate = self
    }
}

extension ViewController: UIDocumentInteractionControllerDelegate {
    func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
        return self
    }

    func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) {
        print("will begin")
    }

    func documentInteractionController(_ controller: UIDocumentInteractionController, didEndSendingToApplication application: String?) {
        print("did end")
    }
}

我还向 Apple 提交了一个错误(问题 ID:34772214)

【问题讨论】:

    标签: ios swift uikit ios11 uidocumentinteraction


    【解决方案1】:

    问题是我试图将 URL 共享到应用程序包中的文件。似乎 Apple 的应用程序有权访问该 URL,但第三方应用程序没有。我解决了这个问题,首先将资源复制到缓存目录,然后使用该缓存目录 URL 进行共享。

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2018-08-16
    • 2018-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-11
    • 1970-01-01
    • 2020-09-16
    相关资源
    最近更新 更多