Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Downloading zip and extracting in main bundle subdirectory at runtime

Tags:

ios

iphone

ipad

I want to extend my iPhone app that the app downloads a zip file into a sub directory then extracts it and then load images which were inside the zip.

Any ideas how to unzip in run-time and the access the images? Would be really happy for some idea.

Greetings,

like image 461
Nando Avatar asked Mar 22 '11 00:03

Nando


Video Answer


2 Answers

I've used ZipArchive with success in the past.

It's pretty ligthweight and simple to use, supports password protection, multiple files inside a ZIP, as well as compress & decompress.

The basic usage is:

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"];
ZipArchive *zipArchive = [[ZipArchive alloc] init];
[zipArchive UnzipOpenFile:filepath Password:@"xxxxxx"];
[zipArchive UnzipFileTo:{pathToDirectory} overWrite:YES];
[zipArchive UnzipCloseFile];
[zipArchive release];
like image 68
Rog Avatar answered Oct 21 '22 03:10

Rog


You cannot extract into your bundle. Use [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] to get the path to a directory you can write to.

You can use the code from http://code.google.com/p/ziparchive/ to extract files from the zip archive.

like image 24
Anomie Avatar answered Oct 21 '22 04:10

Anomie