How to decompress a ZIP file using Objective-C

Source: Internet
Author: User
Tags ziparchive

UseObjective-C decompress the ZIP fileThe tutorial is the content to be introduced in this article.Objective-CHow to comeDecompress the ZIP file.

1. first introduce the libz. dylib framework

2. To begin.

3,Decompress the ZIP fileThe Code is as follows:

 
 
  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,Decompress the ZIP fileThe Code is as follows:

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

Summary: UseObjective-C decompress the ZIP fileThe content of this tutorial has been introduced. I hope this article will help you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.