使用Objective-C解压缩ZIP文件教程是本文要介绍的内容,主要来学习的是在Objective-C如何来解压缩ZIP文件,来看本文详细内容。
1、首先引入libz.dylib框架
2、到http://code.google.com/p/ziparchive/downloads/list下载所需要的第三方文件,并将其导入到项目中。
3、解压缩ZIP文件代码如下:
- ZipArchive* zip = [[ZipArchive alloc] init];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
- NSString* image1 = [dcoumentpath stringByAppendingString:@"/2.png"] ;
- NSString* image2 = [dcoumentpath stringByAppendingString:@"/3.png"] ;
- BOOL ret = [zip CreateZipFile2:l_zipfile];
- ret = [zip addFileToZip:image1 newname:@"2.png"];
- ret = [zip addFileToZip:image2 newname:@"3.png"];
- if( ![zip CloseZipFile2] )
- {
- l_zipfile = @"";
- }
- [zip release];
4、解压缩ZIP文件代码如下:
- ZipArchive* zip = [[ZipArchive alloc] init];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
- NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;
- NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;
- if( [zip UnzipOpenFile:l_zipfile] ) {
- BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
- if( NO==ret ) { }
- [zip UnzipCloseFile];
- }
- [zip release];
小结:使用Objective-C解压缩ZIP文件教程的内容介绍完了,希望通过本文的学习能对你有所帮助!