我正在构建一个从 zip 文件下载大量数据的应用程序。我下载了 zipfile,但想提取 pdf 文件的目录。我正在使用 SSZipArchive,但我的代码不起作用。我想我没有正确解压缩它。
我的代码:
[data writeToFile:filePath atomically:YES];
// Unzipping
NSString *destinationPath = [documentsDir stringByAppendingPathComponent"catalogus"];;
[SSZipArchive unzipFileAtPath:filePath toDestination:destinationPath];
[[NSUserDefaults standardUserDefaults] setValue:destinationPath forKey"catalogus"];
我想在另一个 View Controller 中打开 pdf
NSString *bestand = [[NSUserDefaults standardUserDefaults] valueForKey"catalogus"];
ReaderDocument *testdocument = [ReaderDocument withDocumentFilePath:bestand password:phrase];
当我直接下载 pdf(根本没有压缩)时,我的代码工作正常。
用这个解压:
- (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 toDestinationutputPath delegate:self];
}
并使用此方法从目录中获取 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;
}
关于ios - SSZiparchive 简单解档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16792616/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |