I've successfully downloaded the file but I am unable to save the file. Because I keep getting the error(s):
[SSZipArchive] Error: You don’t have permission to save the file “fileName” in the folder “Folder_Name”.
[SSZipArchive] Error: You don’t have permission to save the file “fileName” in the folder “__MACOSX”.
Any help would be appreciated!
Unzip file function call
 ZipManager.unzipFile(atPath: filePath, delegate: self)
ZipManager.swift
private static let documentsURL: URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
static func unzipFile(atPath path: String, delegate: SSZipArchiveDelegate)
    {
        let destFolder = "/Folder_Name"
        let destPath = documentsURL.appendingPathComponent(destFolder, isDirectory: true)
        let destString = destPath.absoluteString
        
        if ( !FileManager.default.fileExists(atPath: destString) )
        {
            try! FileManager.default.createDirectory(at: destPath, withIntermediateDirectories: true, attributes: nil)
        }
        
        SSZipArchive.unzipFile(atPath: path, toDestination: destString, delegate: delegate)
    }
Thanks to this post I realized its because of this line:
let destString = destPath.absoluteString
I had to change it to:
let destString = documentsURL.relativePath
Which allowed me to greatly simplify my function:
static func unzipFile(atPath path: String) -> Bool
    {
        let destString = documentsURL.relativePath
        let success: Void? = try? SSZipArchive.unzipFile(atPath: path, toDestination: documentsURL.relativePath, overwrite: true, password: nil)
        if success == nil
        {
            return false
        }
        return true
    }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With