xcode SSZiparchive 简单解压
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16792616/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SSZiparchive simple unarchiving
提问by Andrew Ho
I am building an app which downloads a bunch of data from a zip file. I downloaded the zipfile but want to extract the catalog which is a pdf file. I am using SSZipArchive but my code isn't working. I guess I'm not unzipping it correctly.
我正在构建一个应用程序,它从一个 zip 文件下载一堆数据。我下载了 zipfile,但想提取 pdf 文件的目录。我正在使用 SSZipArchive,但我的代码不起作用。我想我没有正确解压缩它。
My code:
我的代码:
[data writeToFile:filePath atomically:YES];
// Unzipping
NSString *destinationPath = [documentsDir stringByAppendingPathComponent:@"catalogus"];;
[SSZipArchive unzipFileAtPath:filePath toDestination:destinationPath];
[[NSUserDefaults standardUserDefaults] setValue:destinationPath forKey:@"catalogus"];
And in another viewcontroller I want to open the pdf
在另一个视图控制器中,我想打开 pdf
NSString *bestand = [[NSUserDefaults standardUserDefaults] valueForKey:@"catalogus"];
ReaderDocument *testdocument = [ReaderDocument withDocumentFilePath:bestand password:phrase];
When i download the pdf directly (not zipped at all) my code works fine.
当我直接下载 pdf(根本没有压缩)时,我的代码工作正常。
回答by Nishant Tyagi
Use this to unzip :
使用它来解压缩:
- (void)Unzipping {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *outputPath = [documentsDirectory stringByAppendingPathComponent:@"/PDFFolder"];
NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"FILENAME.zip"];
NSString *zipPath = filePath;
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
}
and use this method to fetch pdf from directory :
并使用此方法从目录中获取 pdf:
-(NSData *)FetchPDF
{
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/PDFFolder"];
NSString *workSpacePath = [dataPath stringByAppendingPathComponent:@"your_filename.pdf"];
NSData *pdfData = [NSData dataWithContentsOfFile:workSpacePath];
return pdfData;
}