When using the new WKDownloadDelegate, I try to download a file, and the first time it downloads fine, but when I attempt to download the same file again, WKDownloadDelegate invokes this method:
func download(_ download: WKDownload, didFailWithError error: Error, resumeData: Data?)
When I print this to the console:
download(_ download: <WKDownload: 0x7fc58fb2dfd0>, didFailWithError error: The operation couldn’t be completed. (NSURLErrorDomain error -3000.), resumeData: nil
Problem is I can't find any information about this error (-3000), so any suggestions would be nice.
Here is the whole WKDownloadDelegate code
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("------------------")
}