URL에서 zip 파일을 다운로드해야하고 다운로드가 완료되면 비동기식으로 압축을 풀어야합니다. 문제는 여기 FileManager.default.copyItem 언젠가 걸립니다 따라서 즉시 파일 압축을 풀 수 없습니다.Swift - FileManager.default.copyItem을 사용하여 url에서 파일을 성공적으로 다운로드하는 방법을 알고 싶습니다.
func saveZipFile(url: URL, directory: String) -> Void {
let request = URLRequest(url: url)
let task = URLSession.shared.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// Success
if let statusCode = (response as? HTTPURLResponse)?.statusCode {
print("Successfully downloaded. Status code: \(statusCode)")
}
do {
try FileManager.default.copyItem(at: tempLocalUrl as URL, to: FileChecker().getPathURL(filename: url.lastPathComponent, directory: directory))
print("sucessfully downloaded the zip file ...........")
//unziping it
//self.unzipFile(url: url, directory: directory)
} catch (let writeError) {
print("Error creating a file : \(writeError)")
}
} else {
print("Error took place while downloading a file. Error description: %@", error?.localizedDescription);
}
}
task.resume()
}
내가 알고 싶은 초보자 인 파일이 다운로드 말해 및 압축 해제에 사용할 수있는 신속한에서 사용할 수있는 콜백이되어 아래 zip 파일을 다운로드하는 코드입니다. 파일을 압축 해제하기 위해 SSZipArchive 라이브러리를 사용하고 있습니다. 아래
이
SSZipArchive.unzipFile(atPath: path, toDestination: destinationpath)
당신은 u는 샘플 코드를 제공 할 수 있습니다 완료 핸들러 –
같은 콜백 함수를 사용하거나 내가 사용할 수있는 방법을 연결할 수 있습니다 그거야? –