0

我用来下载这本书的代码是..
//创建要下载的源文件的 URL let fileURL = URL(string:myFileURL)

    let sessionConfig = URLSessionConfiguration.default
    let session = URLSession(configuration: sessionConfig)

    let request = URLRequest(url:fileURL!)

    let task = session.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)")

                DispatchQueue.main.async {
                    self.toast(msg: "Download completed")
                    self.activityIndicator.stopAnimating()
                    self.activityIndicator.isHidden = true

                }

            }

            do {
                try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
            } catch (let writeError) {
                print("Error creating a file \(destinationFileUrl) : \(writeError)")
            }

        } else {
            print("Error took place while downloading a file. Error description: %@", error?.localizedDescription);
        }

之后我尝试使用代码从destinationFileUrl解压缩epub文件

let status = SSZipArchive.unzipFile(atPath: destinationFileUrl , toDestination:destPath, delegate:self)

状态值返回 false,因此输出文件夹仅包含没有项目的 META-INF 文件夹

我怎样才能正确解压缩epub

4

1 回答 1

0

请参考这个 -->>解压下载的文件 URL 后没有弹出文件

     var filepath = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
                filepath += "/\(UUID().uuidString)"
                let url = URL(fileURLWithPath: filepath)
                do {
                    try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
                    let done = SSZipArchive.unzipFile(atPath: path!, toDestination: url.path)
                    if done{
                        let items = try FileManager.default.contentsOfDirectory(atPath: url.path)
                        print(items)
                   }
                } catch let error as NSError{
                    print(error)
                }
于 2019-07-29T11:34:01.837 回答