I am performing a task in which I have to zip a PDF file which is store in a document directory and then unzip the file. I am facing issue while unzipping the file, maybe I am not doing at correct location because when I print the location on console and navigate to that location I can see the file.
But while trying the file on that location I am getting error "the operation couldn't be completed no such file or directory".
Following is my code: in which I am decoding a base64 string into zip at a location.
NSData *plainTextData = [NSData dataFromBase64String:base64StringReceivedFromServer];
NSString *docsDir;
NSArray *dirPaths;
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *databasePath = [docsDir stringByAppendingPathComponent:@"demo.zip"];
NSString *absoluteFilePath = [NSString stringWithFormat:@"%@",databasePath];
[plainTextData writeToFile:absoluteFilePath atomically:YES];
2) trying to unzip the file:
NSString *test;
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
objectAtIndex:0];
NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"demo.zip"];
NSString *absoluteFilePath = [NSString stringWithFormat:@"%@",zipFilePath];
NSString *targetDirPath = [documentsDirectory stringByAppendingPathComponent:@"NILESHFOLDER"];
ZipArchive* zipArchive = [[ZipArchive alloc] init];
if( [zipArchive UnzipOpenFile:absoluteFilePath] )
{
if( [zipArchive UnzipFileTo:targetDirPath overWrite:YES] != NO )
{
}
[zipArchive UnzipCloseFile];
}
I think I am not able to write the zip into correct location