我已经成功下载了 zip 文件并在ZipArchive
. 但是现在我必须从解压缩文件的子文件夹中访问图像。解压缩文件夹保存在文档目录中。子文件夹名称总是改变。我使用以下代码解压缩 zip 文件:
NSURL *zipUrl = [NSURL URLWithString:responseString];
NSData *data = [NSData dataWithContentsOfURL:zipUrl options:0 error:&error];
if(!error)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSLog(@"paths..%@",paths);
NSString *path = [paths objectAtIndex:0];
NSString *zipPath = [path stringByAppendingPathComponent:@"zipfile.zip"];
[data writeToFile:zipPath options:0 error:&error];
if(!error)
{
ZipArchive *za = [[ZipArchive alloc] init];
if ([za UnzipOpenFile: zipPath])
{
BOOL ret = [za UnzipFileTo: path overWrite: YES];
if (NO == ret){} [za UnzipCloseFile];
}
}
else
{
NSLog(@"Error saving file %@",error);
}
}
else
{
NSLog(@"Error downloading zip file: %@", error);
}
请帮帮我。提前致谢。