• zip压缩和解压缩


    Zipachieve第三方框架下载地址:

    https://code.google.com/archive/p/ziparchive/downloads

    1.下载完成后解压,将文件拉入项目中,这是可能会报错;

    2.添加libz.1.2.5.tbd,此时运行一下,要是仍然有错可能是ARC的问题,修改不兼容ARC(-fno-objc-arc);

    3.上代码:

    下载一个zip文件:

    NSURL *url=[NSURL URLWithString:@"http://192.168.1.102:8080/zip/JFTestFramework.framework.zip"];
        NSMutableURLRequest *re=[NSMutableURLRequest requestWithURL:url];
        
        [NSURLConnection sendAsynchronousRequest:re queue:[NSOperationQueue new] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
            if (data) {
                NSLog(@"%ld",data.length);
                 [self performSelectorOnMainThread:@selector(saveFramework:) withObject:data waitUntilDone:YES];
            }else{
                
                NSLog(@"加载失败");
            }
           
        }];

    保存下载的压缩包,解压压缩包,并删除原来的压缩包:

    -(void)saveFramework:(NSData*)data{
        NSString *documentDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        NSString *zipPath = [NSString stringWithFormat:@"%@/%@",documentDirectory,@"framework.zip"];
        NSLog(@"1---------%@",zipPath);
       // NSLog(@"%@",data);
       
        NSString *bundlePath = [NSString stringWithFormat:@"%@/%@",documentDirectory,@""];
        [data writeToFile:zipPath atomically:YES];
        
        ZipArchive *zip=[[ZipArchive alloc]init];
        if ([zip UnzipOpenFile:zipPath]) {
            NSLog(@"打开成功");
            if ([zip UnzipFileTo:bundlePath overWrite:YES]) {
                NSLog(@"解压成功");
                [[NSFileManager defaultManager]removeItemAtPath:zipPath error:nil];
                [zip UnzipCloseFile];
            }
            
        }
        ;
    }

    此时打开文件下载路径可以看到下载解压之后的文件:

  • 相关阅读:
    Spring(4)——面向切面编程(AOP模块)
    Spring(3)——装配 Spring Bean 详解
    Spring(2)——Spring IoC 详解
    Spring学习(1)——快速入门
    彼得原理(The Peter Principle)
    默菲定律 [Murphy's Law]
    EXTJS 表单提交
    在java 中,数组与 List<T> 类型的相互转换
    Eclipse 工作目录被破坏,导致Eclipse 打不开
    EXTJS 密码确认与验证
  • 原文地址:https://www.cnblogs.com/sunjianfei/p/5781799.html
Copyright © 2020-2023  润新知