SSZipArchive 使用

2024-05-07  本文已影响0人  小福8090

-(void)unZip

{

    NSString *caches=[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)lastObject];

    NSString *unzipPath = [[NSBundle mainBundle] pathForResource:@"dddddd" ofType:@"zip"];

    NSString *desPath=[caches stringByAppendingPathComponent:@"unzip"];

    UIImageView *image=[[UIImageView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];

    image.backgroundColor=[UIColor redColor];

    [self.viewaddSubview:image];

    BOOLsuccess =  [SSZipArchive unzipFileAtPath:unzipPath toDestination:desPath overwrite:YES password:nil error:nil];;

    if(success) {

        NSLog(@"解压成功");

        NSString*unzippedFilePath = [desPathstringByAppendingPathComponent:@"dddddd.png"];

        NSData*fileData = [NSDatadataWithContentsOfFile:unzippedFilePath];

        dispatch_async(dispatch_get_main_queue(), ^{

                image.image= [UIImageimageWithData:fileData];

            });

        }else{

            NSLog(@"解压失败");

        }

}

上一篇下一篇

猜你喜欢

热点阅读