码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发中的压缩以及解压

时间:2015-07-24 23:57:30      阅读:2678      评论:0      收藏:0      [点我收藏+]

标签:

事实上,在iOS开发中,压缩与解压,我都是采用第三方框架SSZipArchive实现的

gitHub地址:   https://github.com/ZipArchive/ZipArchive

上面有详细的使用方法

因为ZipArchive不支持ARC,所以如果你的工程开启了ARC,那么就需要对ZipArchive设置一下。在ZipArchive.mm编译选项中,增加-fno-objc-arc即可。

最后,需要为工程链接libz.dylib动态链接库

使用示范(压缩):

// 获得mainBundle中所有的png的图片路径
    NSArray *pngs = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
    
    // zip文件路径
    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    NSString *zipFilepath = [caches stringByAppendingPathComponent:@"pngs.zip"];
    
    // 创建zip文件
    [SSZipArchive createZipFileAtPath:zipFilepath withFilesAtPaths:pngs];


 

 解压:

  NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
  NSString *filepath = [caches stringByAppendingPathComponent:@"文件名.zip"];
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
           // 解压(文件大, 会比较耗时,所以放到子线程中解压)
          [SSZipArchive unzipFileAtPath:filepath toDestination:caches];
       });

 

iOS开发中的压缩以及解压

标签:

原文地址:http://www.cnblogs.com/ziyi--caolu/p/4674973.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!