解压 zip 文件不起作用

发布于 2024-09-13 13:52:40 字数 1120 浏览 7 评论 0原文

我是 iPhone 编程新手..有人可以帮我解决以下问题吗

我正在使用以下代码来解压 zip 文件..它不起作用...并打印 NSLog(@"无法解压缩存档");留言

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];

谢谢....

i am new to iPhone programming..can anybody help me out from the following problem

i am using the fallowing code to unarcive a zip file.. its not working... and printing the NSLog(@"Failure To Unzip Archive"); 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];

thank u....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷默言语 2024-09-20 13:52:40

我得到了解决方案...

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

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

这对我有帮助

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];

i got the solution...

the problem is the zip file is not recognized...
i changed the fallowing code

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文