iOS中對文件的解壓縮處理通常都是利用第三方框架,實(shí)現(xiàn)解壓縮掉缺,接下來就來看看吧。
第三方庫:ZipArchive
下載地址:lishichao/ZipArchive · GitHub
使用步驟
1.導(dǎo)入 libz.dylib 框架
2.導(dǎo)入 Main.h
// 解壓文件
NSString *zipPath = @"path_to_your_zip_file";
NSString destinationPath = @"path_to_the_folder_where_you_want_it_unzipped";
/
第一個(gè)參數(shù): 需要解壓縮的文件
第二個(gè)參數(shù): 解壓縮之后放到什么地方
*/
[Main unzipFileAtPath:zipPath toDestination:destinationPath];
// 壓縮文件
NSString *zippedPath = @"path_where_you_want_the_file_created";
NSArray inputPaths = @[[[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpg"],
[[NSBundle mainBundle] pathForResource:@"photo1" ofType:@"jpg"]];
/
打包一個(gè)文件, 壓縮一個(gè)文件
第一個(gè)參數(shù): 壓縮文件的存儲(chǔ)位置
第二個(gè)參數(shù): 需要壓縮的文件
*/
[Main createZipFileAtPath:zippedPath
withFilesAtPaths:inputPaths];
// Zip Directory
[Main createZipFileAtPath:zippedPath
withContentsOfDirectory:inputPaths];