【问题标题】:Error: You don’t have permission to save the file in the folder错误:您无权将文件保存在文件夹中
【发布时间】:2018-01-08 20:44:06
【问题描述】:

我已成功下载文件,但无法保存文件。因为我不断收到错误:

[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”.

任何帮助将不胜感激!

代码

解压文件函数调用

 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)
    }

【问题讨论】:

  • 您不应该将destPath 传递给SSZipArchive.unzipFile 函数吗?
  • @Kymer 不接受String,所以我不能输入URL
  • 嗯...destString 那么?也许您应该稍微清理一下该功能。例如,您似乎没有使用 path 参数。
  • @Kymer 不确定您的意思。我在`SSZipArchive.unzipFile(atPath:path,toDestination:destString,delegate:delegate)`中使用path`
  • 您是否开启了应用沙盒功能?

标签: ios swift ssziparchive


【解决方案1】:

多亏了post,我才意识到这是因为这条线:

let destString = destPath.absoluteString

我不得不把它改成:

let destString = documentsURL.relativePath

这让我大大简化了我的功能:

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
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-06
    • 2016-06-11
    • 1970-01-01
    • 1970-01-01
    • 2019-03-15
    • 1970-01-01
    相关资源
    最近更新 更多