Skip to content

Instantly share code, notes, and snippets.

@francocarbonaro
Created June 6, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save francocarbonaro/2882805 to your computer and use it in GitHub Desktop.
Save francocarbonaro/2882805 to your computer and use it in GitHub Desktop.
Descompactando arquivos no iOS usando a classe ZipArchive
#import "ViewController.h"
#import "ZipArchive.h"
@interface ViewController ()
- (IBAction)unzip:(id)sender;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark - Private Methods
- (IBAction)unzip:(id)sender {
ZipArchive *zip = [ZipArchive new];
//define aonde o arquivo será extraído
//nesse caso ficará dentro de Documents/files/
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"files/"]];
//arquivo a ser extraído
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"file" ofType:@"zip"];
//para arquivos com senha, pasta usar o método UnzipOpenFile:Password
if ([zip UnzipOpenFile:filePath]) {
[zip UnzipFileTo:path overWrite:YES];
}
[zip UnzipCloseFile];
[zip release];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment