UIDocumentInteractionController无法在iOS 11中打开其他应用程序

dre*_*wag 4 uikit ios uidocumentinteraction swift ios11

我的应用程序将PDF分享给另一个第三方应用程序的能力在iOS 11中已经破坏.它显示了共享表,但是当我选择在另一个(第三方)应用程序中打开它时,它只是取消共享表并且什么都不做.

我已经确认的事情:

  • 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")
    }
}
Run Code Online (Sandbox Code Playgroud)

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

dre*_*wag 9

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

  • 非常感谢! (3认同)