1、简介
2、压缩方法
// SSZipArchive压缩
- (void)ssZipArchiveWithFiles {
// Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
// zip压缩包保存路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
// 需要压缩的文件
NSArray *filesPath = @[
@"/Users/apple/Desktop/demo/LaunchImage-2-700-568h@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-700@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-800-667h@2x.png",
@"/Users/apple/Desktop/demo/LaunchImage-2-800-Landscape-736h@3x.png"
];
// 创建不带密码zip压缩包
BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withFilesAtPaths:filesPath];
// 创建带密码zip压缩包
//BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withFilesAtPaths:filesPath withPassword:@"SSZipArchive.zip"];
}
// SSZipArchive压缩
- (void)ssZipArchiveWithFolder {
// Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
// zip压缩包保存路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
// 需要压缩的文件夹路径
NSString *folderPath = @"/Users/apple/Desktop/demo/";
// 创建不带密码zip压缩包
BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:folderPath ];
// 创建带密码zip压缩包
//BOOL isSuccess = [SSZipArchive createZipFileAtPath:path withContentsOfDirectory:folderPath withPassword:@"SSZipArchive.zip"];
}
3、解压方法
// SSZipArchive解压
-(void)uSSZipArchive {
// Caches路径
NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
// 解压目标路径
NSString *destinationPath = [cachesPath stringByAppendingPathComponent:@"SSZipArchive"];
// zip压缩包的路径
NSString *path = [cachesPath stringByAppendingPathComponent:@"SSZipArchive.zip"];
// 解压
BOOL isSuccess = [SSZipArchive unzipFileAtPath:path toDestination:destinationPath];
// 带密码的解压
// 出错原因
NSError *error;
// 解压
BOOL unzip_ok = [SSZipArchive unzipFileAtPath:path toDestination:destinationPath
overwrite:YES password:@"123456" error:&error];
}
4、可能遇到的问题