NSURLSession下载和使用SSZipArchive解压缩

NSURLSession下载和使用SSZipArchive解压缩 

  245人阅读  评论(0)  收藏  举报
  分类:
[objc]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. #import "ViewController.h"  
  2. #import "SSZipArchive.h"  
  3.   
  4. @interface ViewController ()  
  5.   
  6. @end  
  7.   
  8. @implementation ViewController  
  9.   
  10.   
  11. /* 
  12.  NSURLSession下载,默认将下载的文件保存到tmp目录下,如果回调方法里什么事情都没做。 
  13.  tmp目录里面的东西会自动删除。 
  14.  */  
  15.   
  16. - (void)viewDidLoad {  
  17.     [super viewDidLoad];  
  18.       
  19.     //1.url  
  20.     NSString *str = @"http://localhost/images.zip";  
  21.     str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  
  22.     NSURL *url = [NSURL URLWithString:str];  
  23.      
  24.     //2.下载  
  25.     [[[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {  
  26.         NSLog(@"文件的路径%@",location.path);  
  27.           
  28.         //文件保存到什么地方  
  29.         NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];  
  30.          
  31.           
  32.         //解压文件(文件大会比较耗时)  
  33.         [SSZipArchive unzipFileAtPath:location.path toDestination:caches];  
  34.           
  35.     }] resume];  
  36.       
  37. }  
  38.   
  39. @end  

用到的第三方解压缩框架:SSZipArchive

下载地址:https://github.com/samsoffes/ssziparchive

注意:需要引入libz.dylib框架


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值