Разархивирование почтового файла не работает - PullRequest
0 голосов
/ 11 августа 2010

Я новичок в программировании для iPhone. Кто-нибудь может помочь мне решить следующую проблему

Я использую неверный код для разархивирования zip-файла ... он не работает ... и печатаю NSLog (@ "Failure To Unzip Archive"); сообщ

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 голосов
/ 16 августа 2010

я получил решение ...

проблема в том, что 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];
...