使用新的WKDownloadDelegate时,我尝试下载一个文件,第一次下载成功,但当我再次尝试下载同一文件时,WKDownloadDelegate会调用此方法:
当我将此内容打印到控制台时:
func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?)
当我将此内容打印到控制台时:
download(_ download: <WKDownload: 0x7fc58fb2dfd0>, didFailWithError error: The operation couldn’t be completed. (NSURLErrorDomain error -3000.), resumeData: nil
问题是我找不到与此错误(-3000)相关的任何信息,所以希望有任何建议。
这是整个WKDownloadDelegate代码:
public func download(_ download: WKDownload, decideDestinationUsing response: URLResponse, suggestedFilename: String, completionHandler: @escaping (URL?) -> Void) {
let tempDirectory = FileManager.default.temporaryDirectory
let tempFolderName = UUID().uuidString
let tempDirectoryPath = tempDirectory.appendingPathComponent(tempFolderName)
try? FileManager.default.createDirectory(at: tempDirectoryPath, withIntermediateDirectories: false)
let url = tempDirectory.appendingPathComponent(suggestedFilename)
currentDownloadedPreviewItemUrl = url
completionHandler(url)
}
public func downloadDidFinish(_ download: WKDownload) {
guard let currentDownloadedPreviewItemUrl = currentDownloadedPreviewItemUrl else {
print("Download finished but no URL found")
return
}
DispatchQueue.main.async {
let activityVC = UIActivityViewController(activityItems: [currentDownloadedPreviewItemUrl], applicationActivities: nil)
activityVC.popoverPresentationController?.sourceView = self.view
activityVC.popoverPresentationController?.sourceRect = self.view.frame
activityVC.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem
self.present(activityVC, animated: true, completion: nil)
}
}
public func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?) {
debugPrint("------------------")
debugPrint("download(_ download: \(download), didFailWithError error: \(error.localizedDescription), resumeData: \(resumeData)")
debugPrint("------------------")
}