0

我正在处理 zip 和 unzip 对象,为此,我正在使用 ziparchive 类,我能够压缩文件,但是在解压缩文件时出现问题,以下是我的代码

NSString *str1;

ZipArchive *za = [[ZipArchive alloc] init];
[za CreateZipFile2:zipFile];
   NSLog(@"this is my whole new ipad%d",pictureArr.count);
    [self calculation];


for (int i=0;i<[pictureArr count]; i++) {
        NSString *str = [NSString stringWithFormat:@"%@",[pictureArr objectAtIndex:i]];
        NSLog(@"This is my whole new ipad%@",[pictureArr objectAtIndex:i]);
       [za addFileToZip:str newname:[pictureArr objectAtIndex:i]];
    }



//NSString *textPath = [cachePath stringByAppendingPathComponent:@"text.txt"];
NSString *strUrl = [NSString stringWithString:path];
NSString *strunzip=[docspath stringByAppendingPathComponent:strUrl];
NSLog(@"This is my new file path for strXmlName%@",docspath);
[za addFileToZip:strUrl newname:strXmlName];
NSString *fileContent = [docspath stringByAppendingPathComponent:@"strXmlName.zip"];
NSLog(@"This is my final path for%@",fileContent);
NSString *updateURL = [[NSBundle mainBundle] pathForResource:fileContent ofType:@"zip" inDirectory:@"res"];


if ([za UnzipOpenFile:fileContent]) {
    if ([za UnzipFileTo:docspath overWrite:NO]) {
        NSLog(@"Archive unzip success");
        [fileManager removeItemAtPath:docspath error:NULL];
    }
    else {
        NSLog(@"Failure to unzip archive");
    }

    /*7405726724,9227669500-agile infoway
     */

}
else {
    NSLog(@"Failure to open archive");
}


NSData *unzipData = [NSData dataWithContentsOfFile:fileContent];
fileManager = [NSFileManager defaultManager];
[fileManager createFileAtPath:docspath contents:unzipData attributes:nil];

NSLog(@"This is my file");
[za UnzipOpenFile:path];

BOOL success = [za CloseZipFile2];

NSLog(@"Zipped file with result %d",success);

但它直接从if ([za UnzipOpenFile:fileContent])我不知道为什么会发生,我尝试过的是这个这个

所以请指导我谢谢

4

0 回答 0