ios - 如何快速下载 Pdf 文件并在文件管理器中查找
问题描述
我已经使用下面的代码下载了 pdf。我可以在 App Data Container 中找到该文件,但从 app Data Container 中我的设备需要 Mac、x 代码或 iTunes 等。
我可以给 Documents 或其他地方在 iPhone 文件中找到 pdf 的区别路径吗?我可以选择使用 iBook 打开文件,但它不存在。
我下载文件的代码在这里:
func downloadFile(){
let url = "https://www.tutorialspoint.com/swift/swift_tutorial.pdf"
let fileName = "MyFile"
savePdf(urlString: url, fileName: fileName)
}
func savePdf(urlString:String, fileName:String) {
DispatchQueue.main.async {
let url = URL(string: urlString)
let pdfData = try? Data.init(contentsOf: url!)
let resourceDocPath = (FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)).last! as URL
let pdfNameFromUrl = "YourAppName-\(fileName).pdf"
let actualPath = resourceDocPath.appendingPathComponent(pdfNameFromUrl)
do {
try pdfData?.write(to: actualPath, options: .atomic)
print("pdf successfully saved!")
//file is downloaded in app data container, I can find file from x code > devices > MyApp > download Container >This container has the file
} catch {
print("Pdf could not be saved")
}
}
}
解决方案
推荐阅读
- redis - 如何使用 IPV6 接口运行 redis 服务器?
- python - 可以存储在套接字缓冲区中的最大 UDP 数据包数?(Ubuntu)
- ios - 错误的工作日符号 (weekdaySymbols)
- android - Android:光标问题和崩溃的应用程序?
- c# - C# 与 MSSQL 数据库项目未在另一台计算机上运行
- angularjs - 使用 ng-bind-html 隐藏“<>”中的单词
- cassandra - 卡桑德拉内部结构
- css - 在 CSS 中创建这个形状(半管形状)
- c# - 将母版页添加到动态创建的 UI.Page
- php - Eloquent:插入 0.00 而不是实际的浮点值