from the zip file not able to fetch data from the

2019-08-07 06:19发布

i am downloading a zip file and saving in document directory. and then making unzip using the ssziparchive . but not getting any data from the zip file .how to fetch the data .and i am not able to see where is my unzip file .in document directory only i am getting this. enter image description here

i have used this code to make zip as un zip file

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条回答
别忘想泡老子
2楼-- · 2019-08-07 06:32

Zip Data store in Bundle To document directory as below.

  1. get Path from Bundle.

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

    NSData *ZIPData = [NSData dataWithContentsOfFile:StrZIP];
    
  3. Store Zip file in document directory

    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 is unzip using SSZipArchive at documentsPath

    [SSZipArchive unzipFileAtPath:filePath toDestination:documentsPath];
    

OUTPUT :

enter image description here

查看更多
登录 后发表回答