NSURLSession下载和使用SSZipArchive解压缩

#import "ViewController.h"
#import "SSZipArchive.h"

@interface ViewController ()

@end

@implementation ViewController


/*
 NSURLSession下载,默认将下载的文件保存到tmp目录下,如果回调方法里什么事情都没做。
 tmp目录里面的东西会自动删除。
 */

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //1.url
    NSString *str = @"http://localhost/images.zip";
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *url = [NSURL URLWithString:str];
   
    //2.下载
    [[[NSURLSession sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        NSLog(@"文件的路径%@",location.path);
        
        //文件保存到什么地方
        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];
       
        
        //解压文件(文件大会比较耗时)
        [SSZipArchive unzipFileAtPath:location.path toDestination:caches];
        
    }] resume];
    
}

@end

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

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

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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值