目前我正在使用 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";
});
};
尝试将解压缩代码放在后台 GCD 线程上。
关于ios - 解压缩文件进度在 block 内不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22784845/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |