UIDocumentInteractionController 无法处理包含多个页面的大型 pdf 文件。
在我的代码中,
var docController:UIDocumentInteractionController!
...
DispatchQueue.main.async (execute: { [weak self] in
self?.docController = UIDocumentInteractionController(url: pdfFileURL!)
self?.docController.delegate = self
self?.docController.name = pdfFileURL?.lastPathComponent
self?.docController.presentPreview(animated: true)
})
和委托(delegate)方法,
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
这是控制台的警告,
2017-05-26 12:46:51.178894 MyApp [3350:1136818] [default] View service did terminate with error: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} #Remote
下面附上空白图片,
请帮帮我,谢谢。
最佳答案
像这样尝试:
声明:var interaction: UIDocumentInteractionController?
然后添加
interaction = UIDocumentInteractionController(url: URL(string: "<PDF FILE PATH>")!)
interaction.delegate = self
interaction.presentPreview(animated: true) // IF SHOW DIRECT
或者如果需要任何建议弹出
interaction.presentOpenInMenu(from: /*<SOURCE BUTTON FRAME>*/, in: self.view, animated: true)
实现委托(delegate) -> UIDocumentInteractionControllerDelegate
public func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
public func documentInteractionControllerDidEndPreview(_ controller: UIDocumentInteractionController) {
interaction = nil
}
关于ios - Swift:UIDocumentInteractionController 不工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44196066/