Question

Currently I am using https://github.com/mattconnolly/ZipArchive library to unzip the compressed folder.It is working fine but I want to also show the unzip progress with it.I am getting unzip progress with ZipArchiveProgressUpdateBlock but progress bar is not showing the progress.check the code below :

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];

What I have tried so far :

I also try to put the progress bar ui changes in main thread but it is still not working

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";
        });
    };
Was it helpful?

Solution

Try putting the unzip code on a background GCD thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top