2

我正在构建一个从 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"];

在另一个视图控制器中,我想打开 pdf

NSString *bestand = [[NSUserDefaults standardUserDefaults] valueForKey:@"catalogus"];
ReaderDocument *testdocument = [ReaderDocument withDocumentFilePath:bestand password:phrase];

当我直接下载pdf(根本没有压缩)时,我的代码工作正常。

4

1 回答 1

4

使用它来解压缩:

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

}

并使用此方法从目录中获取 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;
}
于 2013-05-28T12:57:45.440 回答