psk
psk

Reputation: 192

Unzip file using SSZipArchive not extracting zip file

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

Upvotes: 1

Views: 1783

Answers (3)

Debasis
Debasis

Reputation: 11

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

Upvotes: 0

Vikas Rajput
Vikas Rajput

Reputation: 1874

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.

Upvotes: 0

Debasis
Debasis

Reputation: 11

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

Upvotes: 1

Related Questions