Created
June 6, 2012 15:47
-
-
Save francocarbonaro/2882805 to your computer and use it in GitHub Desktop.
Descompactando arquivos no iOS usando a classe ZipArchive
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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