ios - Swift:UIDocumentInteractionController 不工作?

标签 ios swift uidocumentinteraction

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

下面附上空白图片,

enter image description here

请帮帮我,谢谢。

最佳答案

像这样尝试:

声明: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/

相关文章:

string - NSFontAttributeName 已更改为 String

ios - Swift WKWebView 在 didFailProvisionalNavigation 上崩溃

ios - UIdocumentInteractionController 无法在 swift 4 中显示 PDF 文件

ios - UIDocumentInteractionController 操作/选项菜单在首次启动时不可见

iOS 发布到 Instagram 不工作

ios - MKMapView 不保持旋转

ios - 重新加载 View Controller 后如何仍然显示progressView的进度?

ios - Facebook iOS SDK : Login with Facebook failed

ios - captureStillImageAsynchronously 在特定时间不起作用

ios - Swift:用于 uiimageview 的 UITapGestureRecognizer 在自定义 View 中终止应用程序