使用Objective-C解壓縮ZIP檔案教程

來源:互聯網
上載者:User

使用Objective-C解壓縮ZIP檔案教程是本文要介紹的內容,主要來學習的是在Objective-C如何來解壓縮ZIP檔案,來看本文詳細內容。

1、首先引入libz.dylib架構

2、到http://code.google.com/p/ziparchive/downloads/list下載所需要的第三方檔案,並將其匯入到項目中。

3、解壓縮ZIP檔案代碼如下:

 
  1. ZipArchive* zip = [[ZipArchive alloc] init];  
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  3. NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;  
  4. NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;  
  5.  
  6. NSString* image1 = [dcoumentpath stringByAppendingString:@"/2.png"] ;  
  7. NSString* image2 = [dcoumentpath stringByAppendingString:@"/3.png"] ;  
  8.  
  9. BOOL ret = [zip CreateZipFile2:l_zipfile];  
  10. ret = [zip addFileToZip:image1 newname:@"2.png"];  
  11. ret = [zip addFileToZip:image2 newname:@"3.png"];  
  12. if( ![zip CloseZipFile2] )  
  13. {  
  14.     l_zipfile = @"";  
  15. }  
  16. [zip release]; 

4、解壓縮ZIP檔案代碼如下:

 
  1. ZipArchive* zip = [[ZipArchive alloc] init];  
  2. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  3. NSString *dcoumentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;  
  4. NSString* l_zipfile = [dcoumentpath stringByAppendingString:@"/test.zip"] ;  
  5. NSString* unzipto = [dcoumentpath stringByAppendingString:@"/test"] ;  
  6. if( [zip UnzipOpenFile:l_zipfile] ) {  
  7.     BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];  
  8.     if( NO==ret ) { }  
  9.     [zip UnzipCloseFile];  
  10. }  
  11. [zip release]; 

小結:使用Objective-C解壓縮ZIP檔案教程的內容介紹完了,希望通過本文的學習能對你有所協助!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.