在块内解压缩文件进度不起作用

时间:2014-04-01 11:42:50

标签: ios iphone objective-c progress-bar unzip

目前我正在使用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";
        });
    };

1 个答案:

答案 0 :(得分:1)

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