Commit 8acee64f authored by Steven杜宇's avatar Steven杜宇

// plan

parent a56962db
......@@ -238,7 +238,9 @@ class YHPlanShareViewController: YHBaseViewController {
}
YHHUD.show(.progress(message: "下载中..."))
let task = URLSession.shared.downloadTask(with: url) { [weak self] (locationUrl, _, error) in
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
let task = session.downloadTask(with: url) { [weak self] (locationUrl, response, error) in
DispatchQueue.main.async {
YHHUD.hide()
guard let self = self else { return }
......@@ -247,6 +249,9 @@ class YHPlanShareViewController: YHBaseViewController {
YHHUD.flash(message: "下载PDF失败")
return
}
if let res = response {
printLog(res.suggestedFilename)
}
self.savePDF(sourceUrl: url, locationUrl: locationUrl)
}
}
......@@ -256,17 +261,6 @@ class YHPlanShareViewController: YHBaseViewController {
func savePDF(sourceUrl: URL, locationUrl: URL) {
let fileManager = FileManager.default
// 创建子文件夹如果不存在
if !fileManager.fileExists(atPath: self.planDocumentFileUrl.path) {
do {
try fileManager.createDirectory(at: self.planDocumentFileUrl, withIntermediateDirectories: true, attributes: nil)
print("目录已创建: \(self.planDocumentFileUrl.path)")
} catch {
print("创建目录失败: \(error.localizedDescription)")
return
}
}
// 保存文件到 plan 目录
let lastComponent = sourceUrl.lastPathComponent
......@@ -278,6 +272,7 @@ class YHPlanShareViewController: YHBaseViewController {
}
try fileManager.moveItem(at: locationUrl, to: destinationURL)
print("文件已保存到: \(destinationURL.path)")
print("文件源地址: \(locationUrl.path)")
YHHUD.flash(message: "下载PDF成功")
} catch {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment