OGeek|极客世界-中国程序员成长平台

标题: ios - 解压缩文件进度在 block 内不起作用 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 21:10
标题: ios - 解压缩文件进度在 block 内不起作用

目前我正在使用 https://github.com/mattconnolly/ZipArchive库来解压缩压缩文件夹。它工作正常,但我还想用它显示解压缩进度。我正在使用 ZipArchiveProgressUpdateBlock 获得解压缩进度,但进度条没有显示进度。检查下面的代码:

ZipArchive *zip = [[ZipArchive alloc] init];

    self.progressBarDownload.progress = 0;

    self.lblProgress.text = @"Wait unzipping file";

    ZipArchiveProgressUpdateBlock progressBlock = ^ (int percentage, int filesProcessed, int numFiles) {
        NSLog(@"total %d, filesProcessed %d of %d", percentage, filesProcessed, numFiles);
            self.progressBarDownload.progress = filesProcessed / numFiles;
            if(filesProcessed==numFiles)
                self.lblProgress.text = @"Done";
    };

    zip.progressBlock = progressBlock;

    //open file
    [zip UnzipOpenFile:path];

    //unzip file to
    [zip UnzipFileTo:[dirArray objectAtIndex:0] overWrite:YES];

到目前为止我所做的尝试:

我也尝试将进度条ui更改放在主线程中,但仍然无法正常工作

ZipArchiveProgressUpdateBlock progressBlock = ^ (int percentage, int filesProcessed, int numFiles) {
        NSLog(@"total %d, filesProcessed %d of %d", percentage, filesProcessed, numFiles);
        dispatch_sync(dispatch_get_main_queue(), ^{
            //Your code goes in here
            NSLog(@"Main Thread Code");
            self.progressBarDownload.progress = filesProcessed / (float)numFiles;
            if(filesProcessed==numFiles)
                self.lblProgress.text = @"Done";
        });
    };



Best Answer-推荐答案


尝试将解压缩代码放在后台 GCD 线程上。

关于ios - 解压缩文件进度在 block 内不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784845/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4