2010-08-10 32 views
0

我是新來的iPhone programming..can人幫助我從下面的問題取消歸檔zip文件不能正常工作

我使用休耕代碼unarcive一個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]; 

感謝ü....

回答

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

我認爲這可能不可能在設備上。 – ajay 2010-12-29 05:00:46

+0

我在may應用程序中使用了這個功能,並且在我的設備上也成功運行了 – rockey 2010-12-29 08:52:43

+0

下載了「ZipArchive」opensource文件夾,您將擁有minizip文件夾和ZipArchive文件,您需要導入「ZipArchive.h」 – rockey 2010-12-29 09:01:43