Search code examples
iosobjective-cmacosunzipssziparchive

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

Solution

  • 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.