我的应用程序将 PDF 共享到另一个第三方应用程序的功能在 iOS 11 中已损坏。它显示了共享表,但是当我选择在不同的(第三方)应用程序中打开它时,它只是关闭了共享表并且什么都不做。
我已经确认的事情:
UIActivityViewController。共享 URL 会产生相同的行为。共享原始数据允许您“创建 PDF”,然后共享该 PDF 确实有效(但用户体验很糟糕)。有没有其他人遇到过这种情况或对如何解决它有任何想法?
这是显示问题的示例应用程序的完整代码。我在一个新的“单一 View ”应用程序中创建了它。 Storyboard只有两个按钮连接到两个 Action 。
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 进行共享。
关于ios - UIDocumentInteractionController 不会在 iOS 11 中打开其他应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46531572/