Swi*_*Boy 3 pdf preview downloadfile ios swift
我已经使用下面的代码下载了 pdf,我也可以在 App Data Container 中找到该文件,但是从 App Data Container 中,我的设备需要 Mac、x 代码或 iTunes 等。我的问题是,我可以给出一个区分路径让说文档或在哪里可以找到 iPhone 文件中的 pdf,我可以选择用 iBook 打开文件,但它也不在那里
热烈欢迎任何建议我已经尝试了多个指南和解决方案,但遇到了同样的问题(文件下载,但在 iPhone 中找不到),但我下载文件的代码之一在这里很抱歉,如果问题令人困惑,我是这一切的新手
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")
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过将以下几行添加到您的Info.plist文件中,配置您的应用程序,使其文件显示在“文件”应用程序中。
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
Run Code Online (Sandbox Code Playgroud)
或者
就像下面使用 Xcode
注意:请记住,您必须运行 iOS 11 或更高版本。
| 归档时间: |
|
| 查看次数: |
4421 次 |
| 最近记录: |