UIDocumentInteractionController无法在iOS 11中打开其他应用 [英] UIDocumentInteractionController does not open other app in iOS 11

查看:101
本文介绍了UIDocumentInteractionController无法在iOS 11中打开其他应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序与另一个第三方应用程序共享PDF的功能在iOS 11中已损坏.它显示了共享表,但是当我选择在其他(第三方)应用程序中打开它时,它只是关闭了共享表,什么都不做.

My apps ability to share a PDF to another third party app has broken in iOS 11. It shows the share sheet but when I choose to open it in a different (third-party) app, it simply dismisses the share sheet and does nothing.

我确认的事情:

  • willBeginSending和didEndSending的委托方法都被称为
  • 打开诸如Mail或Notes之类的第一方应用程序可以正常工作
  • 文档选择器仍在内存中
  • 呈现预览效果很好,但是预览内部的共享按钮仍然无法打开第三方应用程序
  • 我也尝试过使用 UIActivityViewController .共享URL会产生相同的行为.共享原始数据使您可以创建PDF",然后共享PDF确实有效(但是用户体验糟透了).
  • The delegate methods for willBeginSending and didEndSending are both called
  • Opening first party apps like Mail or Notes works fine
  • The document picker is still in memory
  • Presenting a preview works fine but then the share button from inside the preview still will not open third party apps
  • I have also tried using a UIActivityViewController. Sharing a URL produces the same behavior. Sharing the raw data allows you to "Create a PDF" and then sharing that PDF does actually work (but that user experience sucks).

其他人是否经历过此事或对如何解决有任何想法?

以下是显示问题的示例应用程序的完整代码.我是在新的单视图"应用中创建的.情节提要只有两个按钮与这两个动作挂钩.

Here is the full code of an example app that shows the problem. I created it in a new "single view" app. The storyboard only has two buttons hooked up to the two actions.

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)

推荐答案

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

The problem was that I was trying to share a URL to a file inside the app bundle. It seems Apple's apps have permission to access that URL but third-party apps don't. I solved this by first copying the resource to the cache directory and then using that cache directory URL for sharing.

这篇关于UIDocumentInteractionController无法在iOS 11中打开其他应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆