1 -(void)zipArchiveWithFiles
2 {
3 //创建解压缩对象
4 ZipArchive *zip = [[ZipArchive alloc]init];
5 //Caches路径
6 NSString *cachesPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
7 //zip压缩包保存路径
8 NSString *path = [cachesPath stringByAppendingPathComponent:@"ZipArchive.zip"];//创建不带密码zip压缩包
9 //创建zip压缩包
10 [zip CreateZipFile2:path];
11 //创建带密码zip压缩包
12 //[zip CreateZipFile2:path Password:@"ZipArchive.zip"];
13 //添加到zip压缩包的文件
14 [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-700-568h@2x.png" newname:@"1.png"];
15 [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-700@2x.png" newname:@"2.png"];
16 [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-800-667h@2x.png" newname:@"3.png"];
17 [zip addFileToZip:@"/Users/apple/Desktop/demo/LaunchImage-2-800-Landscape-736h@3x.png" newname:@"4.png"];
18 //关闭压缩
19 BOOL success = [zip CloseZipFile2];
20 }