jac*_*rln 3 ios swift ssziparchive
我正在尝试使用SSZipArchive框架解压缩文件.
let unzipper = SSZipArchive.unzipFileAtPath(String(document), toDestination: String(documentsUrl))
Run Code Online (Sandbox Code Playgroud)
这就是我目前正在尝试解压缩文件,这里是文件的路径:
unzipFileAtPath - Document at path: file:///private/var/mobile/Containers/Data/Application/94ADDB12-78A2-4798-856D-0626C41B7AC2/Documents/tSOUTrIayb.zip
false
我试图将它解压缩到这条路径:
NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!
Run Code Online (Sandbox Code Playgroud)
不幸的是,它似乎没有工作,每次没有任何新的保存到我打印出来的文档目录中.我还打印了'unzipper'变量,它只是打印false,无论这意味着什么.
我找不到该框架的任何文档,所以我不完全确定如何使这个工作
假设您已经实现了所有功能,那么还可以通过几个步骤提供解决方案
SSZipArchive从演示文稿中拖动文件夹,您可以从此处下载.
写#import "SSZipArchive.h”在yourProjectname-Bridging-Header.h,如果你已经有了.否则,创建上面提到的新头文件.
如果要使用委托方法,请将委托设置为class
class YourViewController: UIViewController, SSZipArchiveDelegate {.......
Run Code Online (Sandbox Code Playgroud)为了创建zip表单文件夹,我已经将示例文件夹添加到项目(主程序包)
首先在文档目录中创建要保存zip文件的文件夹
var paths = NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true)
let documentsDir = paths[0]
let zipPath = documentsDir.stringByAppendingString("/MyZipFiles") // My folder name in document directory
let fileManager = NSFileManager.defaultManager()
let success = fileManager.fileExistsAtPath(zipPath) as Bool
if success == false {
do {
try! fileManager.createDirectoryAtPath(zipPath, withIntermediateDirectories: true, attributes: nil)
}
}
Run Code Online (Sandbox Code Playgroud)现在创建zip文件
var inputPath = NSBundle.mainBundle().resourcePath
inputPath = inputPath!.stringByAppendingString("/Sample") // My folder which already put into project
let archivePath = zipPath.stringByAppendingString(“/Demo.zip") // Sample folder is going to zip with name Demo.zip
SSZipArchive.createZipFileAtPath(archivePath, withContentsOfDirectory:inputPath)
Run Code Online (Sandbox Code Playgroud)用于解压缩文档目录中的文件创建文件夹(要保存的位置)
let destPath = zipPath.stringByAppendingString("/Hello")
let fileManager = NSFileManager.defaultManager()
let success = fileManager.fileExistsAtPath(destPath) as Bool
if success == false {
do {
try! fileManager.createDirectoryAtPath(destPath, withIntermediateDirectories: true, attributes: nil)
}
}
Run Code Online (Sandbox Code Playgroud)解压缩文件夹
SSZipArchive.unzipFileAtPath(archivePath, toDestination:destPath, delegate:self)
Run Code Online (Sandbox Code Playgroud)打印您的路径,您可以检查您的文件是否已保存
print(zipPath)
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
6021 次 |
| 最近记录: |