1. 程式人生 > >iOS 壓縮與解壓縮的原理

iOS 壓縮與解壓縮的原理

使用第三方框架SSZipArchive解壓縮;(匯入框架檔案,在link binary with libraries中新增lib.tbd;)

-(void)zip{

    //壓縮

    [SSZipArchivecreateZipFileAtPath:@"/Users/apple/Desktop/222.zip"withContentsOfDirectory:@"/Users/apple/Desktop/11111"];

}

//從網路下載zip包,解壓縮

- (void)getZIP{

NSURL *url = [NSURLURLWithString:@"http://127.0.0.1/1.zip"];

    [[[NSURLSession

sharedSession] downloadTaskWithURL:url completionHandler:^(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error) {

//location zip包下載到本地的路徑

        NSLog(@"%@",location.path);

        //解壓

        [SSZipArchiveunzipFileAtPath:location.pathtoDestination:@"/Users/apple/Desktop/11111"];

    }] resume];

}