Unzip file using SSZipArchive not extracting zip file

1.7k Views Asked by At

I am downloading a zipped folder using AFNetworking library, file is downloading but when i am trying to Un zip that zip folder, it is not opening. On mac machine it is also not extracting on double click and by Archive Utility.

NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
    NSURL *documentsDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:NO error:nil];
    return [documentsDirectoryURL URLByAppendingPathComponent:[response suggestedFilename]];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
    NSLog(@"File downloaded to: %@", filePath);
    [SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];
}];
3

There are 3 best solutions below

0
Vikas Rajput On BEST ANSWER

try this

   NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
   NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"vikas.sqlite"];
   NSString *outputPath = [paths objectAtIndex:0];
   [SSZipArchive unzipFileAtPath:path toDestination:outputPath delegate:self];

Unzip file will be on Output Path.

2
Debasis On

Instead of

[SSZipArchive unzipFileAtPath:[filePath path] toDestination: [[filePath path] stringByDeletingLastPathComponent]];

use:

[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath overwrite:NO password:nil error:nil]

to unzip the file

0
Debasis On

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;

NSString *destinationPath = [NSString stringWithFormat:@"%@/filepath",basepath]];
[SSZipArchive basePath toDestination:destinationPath overwrite:NO password:nil error:nil];