0

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

ありがとう....

4

1 に答える 1

0

私は解決策を得ました...

問題は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];
于 2010-08-16T13:02:20.493 に答える