需要用到一个名叫ZipArchive的开源工具
需要使用前将一些有retain,release的语句删掉
下载地址:http://code.google.com/p/ziparchive/wiki/PageName
用法:
1)将开源文件引入工程,并#import "ZipArchive.h"
2)解压
ZipArchive *za = [[ZipArchive alloc] init];
if ([za UnzipOpenFile:zipPath]) {
BOOL ret = [za UnzipFileTo:unzipPath overWrite:YES];
if (NO == ret) {
NSLog(@"unzip file failure.....");
}
NSLog(@"zip fininshed...");
[za UnzipCloseFile];
}
3) 创建并压缩文件
BOOL ret = [zip CreateZipFile2:l_zipfile];
// OR
BOOL ret = [zip CreateZipFile2:l_zipfile Password:@"your password"]; //
//if the Password is empty, will get the same effect as [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:l_photo newname:@"photo.jpg"];
if( ![zip CloseZipFile2] )
{
// error handler here
}
[zip release];