使用Objective-C解压缩ZIP文件教程

移动开发 iOS
使用Objective-C解压缩ZIP文件教程是本文要介绍的内容,主要来学习的是在Objective-C如何来解压缩ZIP文件,来看本文详细内容。

使用Objective-C解压缩ZIP文件教程是本文要介绍的内容,主要来学习的是在Objective-C如何来解压缩ZIP文件,来看本文详细内容。

1、首先引入libz.dylib框架

2、到http://code.google.com/p/ziparchive/downloads/list下载所需要的第三方文件,并将其导入到项目中。

3、解压缩ZIP文件代码如下:

  1. ZipArchive* zip = [[ZipArchive alloc] init];  
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  3. NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;  
  4. NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;  
  5.  
  6. NSString* image1 = [dcoumentpath stringByAppendingString:@"/2.png"] ;  
  7. NSString* image2 = [dcoumentpath stringByAppendingString:@"/3.png"] ;  
  8.  
  9. BOOL ret = [zip CreateZipFile2:l_zipfile];  
  10. ret = [zip addFileToZip:image1 newname:@"2.png"];  
  11. ret = [zip addFileToZip:image2 newname:@"3.png"];  
  12. if( ![zip CloseZipFile2] )  
  13. {  
  14.     l_zipfile = @"";  
  15. }  
  16. [zip release]; 

4、解压缩ZIP文件代码如下:

  1. ZipArchive* zip = [[ZipArchive alloc] init];  
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  3. NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;  
  4. NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;  
  5. NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;  
  6. if( [zip UnzipOpenFile:l_zipfile] ) {  
  7.     BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];  
  8.     if( NO==ret ) { }  
  9.     [zip UnzipCloseFile];  
  10. }  
  11. [zip release]; 

小结:使用Objective-C解压缩ZIP文件教程的内容介绍完了,希望通过本文的学习能对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2012-05-10 09:43:28

2011-08-16 10:23:04

Objective-CNSAutoreleaXcode常用键

2011-07-08 13:49:46

Objective-C UUID

2011-07-27 17:10:30

Objective-C 持久化

2011-08-05 14:03:39

Objective-C 对象 模板

2018-09-14 16:18:26

Linux压缩文件应用程序

2011-07-29 16:08:31

Objective-C 内存

2011-08-22 09:48:16

WindowsObjective-C

2011-08-15 17:47:13

Objective-CisMemberOfC

2011-07-22 15:10:51

Objective-C 文件

2011-08-16 13:43:40

Objective-C文件cocoa

2011-08-17 10:00:12

Objective-CProperty

2011-07-21 09:42:27

Objective-C 内存 Autoreleas

2013-03-27 12:54:00

iOS开发Objective-C

2011-05-11 11:20:26

Objective-C

2011-05-11 15:58:34

Objective-C

2013-06-20 10:40:32

Objective-C实现截图

2011-07-27 16:18:42

Objective-c 协议

2011-08-17 09:55:45

Objective-CCategory

2011-07-19 15:15:09

Objective-C 内存
点赞
收藏

51CTO技术栈公众号