我已成功下載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);
}
請幫我。 在此先感謝。