取消归档zip文件无效

时间:2010-08-10 21:28:51

标签: iphone unzip zipfile

我是iPhone编程新手。可以帮助我解决以下问题

我正在使用以下代码来解压缩zip文件..它无法工作...并打印NSLog(@“未能解压缩存档”); MSG

self.fileManager = [NSFileManager defaultManager];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);

self.documentsDir = [paths objectAtIndex:0];

NSString *filePath = [NSString stringWithFormat:@"%@/temp", self.documentsDir];

NSString *updateURL = [[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"bmlgg.zip"];


NSLog(@"Checking update at : %@", updateURL);

NSLog(@"Checking filepath at : %@", filePath);


    ZipArchive *zipArchive = [[ZipArchive alloc] init];

    if([zipArchive UnzipOpenFile:updateURL]) {

        if ([zipArchive UnzipFileTo:filePath overWrite:YES]) {
            //unzipped successfully
            NSLog(@"Archive unzip Success");
            //[self.fileManager removeItemAtPath:filePath error:NULL];
        } else {
            NSLog(@"Failure To Unzip Archive");             
        }

    } else  {
        NSLog(@"Failure To Open Archive");
    }

    [zipArchive release];
谢谢你......

1 个答案:

答案 0 :(得分:0)

我得到了解决方案......

问题是zip文件无法识别...  我更改了以下代码

NSString *updateURL = [[NSBundle mainBundle] pathForResource:@"bmlg" ofType:@"zip" inDirectory:@"res"];

this helped me

self.fileManager = [NSFileManager defaultManager];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);

self.documentsDir = [paths objectAtIndex:0];

NSString *filePath = [NSString stringWithFormat:@"%@/temp", self.documentsDir];

NSString *updateURL = [[NSBundle mainBundle] pathForResource:@"bmlg" ofType:@"zip" inDirectory:@"res"];


[fileManager createDirectoryAtPath:filePath withIntermediateDirectories:NO  attributes:nil  error:nil];


       if([fileManager fileExistsAtPath:updateURL]) {
        NSLog(@"File exists at path: %@", updateURL);
    } else {
        NSLog(@"File does not exists at path: %@", updateURL);
    }

    NSLog(@"Checking update at : %@", updateURL); 

    NSLog(@"Checking filepath at : %@", filePath);


    ZipArchive *zipArchive = [[ZipArchive alloc] init];

    if([zipArchive UnzipOpenFile:updateURL]) {

        if ([zipArchive UnzipFileTo:filePath overWrite:YES]) {
            //unzipped successfully
            NSLog(@"Archive unzip Success");
            //[self.fileManager removeItemAtPath:filePath error:NULL];
        } else {
            NSLog(@"Failure To Unzip Archive");             
        }

    } else  {
        NSLog(@"Failure To Open Archive");
    }

    [zipArchive release];