14w*_*wml 3 ios swift ssziparchive
我已经成功下载了该文件,但我无法保存该文件.因为我不断收到错误:
[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”.
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
解压缩文件函数调用
ZipManager.unzipFile(atPath: filePath, delegate: self)
Run Code Online (Sandbox Code Playgroud)
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)
}
Run Code Online (Sandbox Code Playgroud)
14w*_*wml 11
感谢这篇文章我意识到它是因为这一行:
let destString = destPath.absoluteString
Run Code Online (Sandbox Code Playgroud)
我不得不把它改成:
let destString = documentsURL.relativePath
Run Code Online (Sandbox Code Playgroud)
这让我大大简化了我的功能:
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
}
Run Code Online (Sandbox Code Playgroud)