关闭

iOS开发之解压缩zip文件

141人阅读 评论(0) 收藏 举报
分类:

转载自:   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文件
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:109940次
    • 积分:2338
    • 等级:
    • 排名:第15951名
    • 原创:107篇
    • 转载:122篇
    • 译文:3篇
    • 评论:6条
    最新评论