【问题标题】:Is it possible to save PDF file directly into the file without using UIActivityViewController or UIDocumentInteractionController iOS?是否可以在不使用 UIActivityViewController 或 UIDocumentInteractionController iOS 的情况下将 PDF 文件直接保存到文件中?
【发布时间】:2018-12-06 13:02:05
【问题描述】:

我需要将 PDF 文档从 URL 保存到设备中。是否可以在不使用 UIActivityViewController 或 UIDocumentInteractionController 的情况下保存 PDF 并从设备文件管理器访问它。

【问题讨论】:

  • 一些答案​​是这样的:stackoverflow.com/questions/51759148/…
  • 想想在遥远的过去,我可能也做过同样的事情!!如果我没记错的话,我使用 CoreGraphics 创建了 PDF。完成后使用 NSFileManager 写入/获取文件。不用说,您将不得不手动跟踪文件 URL。创建 PDF 检查developer.apple.com/library/archive/documentation/2DDrawing/…
  • 我的要求不同。已经有一个pdf,我们可以通过它的url访问它。然后我需要下载它并在pdf页面上添加一些cmets。然后我需要重新发送到服务器。
  • 您能详细说明一下吗?您是从远程获取 PDF 还是什么?
  • 是的...我将从服务器获取pdf的url..我们可以下载并保存到文档目录或文件中。但是当我尝试通过 adobe reader 应用程序打开它时,下载的 pdf 将不会显示。

标签: ios swift


【解决方案1】:

在 Info.plist 中添加这 2 个键:LSSupportsOpeningDocumentsInPlaceUIFileSharingEnabled。并将 YES 设置为两者的值。

现在您将能够使用“文件”应用查看您的应用保存在 Documents Directory 中的任何文件。

【讨论】:

  • 我可以在设置 LSSupportsOpeningDocumentsInPlace 和 UIFileSharingEnabled 后使用 adobe reader 的 URL 架构打开保存的 pdf。有什么想法吗??
【解决方案2】:

Swift 5.0 和 iOS13

let documentController = UIDocumentPickerViewController(url: exportToURL, in: .exportToService)
self.present(documentController, animated: true, completion: nil)

exportToURL 表示要保存到 iPhone Files 应用程序中的任何文件的应用程序本地 URL。

【讨论】:

    猜你喜欢
    • 2019-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    相关资源
    最近更新 更多