从zip文件无法从文档目录中获取数据

时间:2015-01-21 06:19:59

标签: ios objective-c iphone ssziparchive

我正在下载一个zip文件并保存在文档目录中。然后使用ssziparchive进行解压缩。但是没有从zip文件中获取任何数据。如何获取数据。我无法看到我的解压缩文件在哪里。仅在文档目录中我得到了这个。 enter image description here

我使用此代码将zip设为un zip文件

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:@"image.zip"];
    NSString *zipPath =fullPath;
    NSString *destinationPath =[documentsDirectory  stringByAppendingPathComponent:@"unZipimage"];
    NSLog(@"zip path==%@",zipPath);
    NSLog(@"dest path==%@",destinationPath);
  //
    [SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath];

1 个答案:

答案 0 :(得分:1)

Zip数据存储在Bundle To Document目录中,如下所示。

  1. 从Bundle获取路径。

     NSString *StrZIP = [[NSBundle mainBundle] pathForResource:@"TestZIP" ofType:@"zip"];
    
  2. Zip转换为NSData

    NSData *ZIPData = [NSData dataWithContentsOfFile:StrZIP];
    
  3. 将Zip文件存储在文档目录

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
    NSString *filePath = [documentsPath stringByAppendingPathComponent:@"TestZIP.zip"]; //Add the file name
    [ZIPData writeToFile:filePath atomically:YES]; //Write the file
    
  4. TeztZIP使用documentsPath

    上的SSZipArchive解压缩
    [SSZipArchive unzipFileAtPath:filePath toDestination:documentsPath];
    
  5. 输出:

    enter image description here