iOS开发之解压缩zip文件

转载自:   http://blog.sina.com.cn/s/blog_833996210100udkl.html

从http://code.google.com/p/ziparchive/ 上下载ZipArchive.zip,解压后将代码加入工程中,把zlib库添加到工程中

压缩
  1.    ZipArchive* zip = [[ZipArchive alloc] init];
  2.          
  3.    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  4.    NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
  5.    NSString * zipFile = [dcoumentpath stringByAppendingString:@"/images.zip"] ;
  6.          
  7.     NSString *image1 = [dcoumentpath stringByAppendingString:@"/犬夜叉.jpg"] ;   
  8.     NSString *image2 = [dcoumentpath stringByAppendingString:@"/杀生丸.jpg"] ;      
  9.          
  10.     BOOL result = [zip CreateZipFile2:zipFile];
  11.     result = [zip addFileToZip:image1 newname:@"犬夜叉.jpg"];
  12.     result = [zip addFileToZip:image2 newname:@"杀生丸.jpg"];
  13.     if( ![zip CloseZipFile2] ){
  14.               zipFile = @"";
  15.     }
  16.     [zip release];

  1. 解压缩
  2.     ZipArchive* zip = [[ZipArchive alloc] init];
  3.     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  4.     NSString *documentPath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
    1.     NSString* zipFile = [dcoumentpath stringByAppendingString:@"/images.zip"] ;
    2.     NSString* unZipTo = [dcoumentpath stringByAppendingString:@"/images"] ;
    3.     if( [zip UnzipOpenFile:zipFile] ){
    4.            BOOL result = [zip UnzipFileTo:unZipTo overWrite:YES];
    5.            if( NO==result ){
    6.                       //添加代码
    7.            }
    8.           [zip UnzipCloseFile];
    9.      }
    10.      [zip release];
  5. iOS开发之解压缩zip文件参考了一下网上的代码,请大家多多指教iOS开发之解压缩zip文件

你可能感兴趣的:(浏览器项目)