Error: You don’t have permission to save the file in the folder
Error: You don’t have permission to save the file in the folder
我已成功下载文件,但无法保存文件。因为我不断收到错误消息:
[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)
}
多亏了这个我意识到这是因为这一行:
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
}
我已成功下载文件,但无法保存文件。因为我不断收到错误消息:
[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)
}
多亏了这个
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
}