Wednesday, July 22, 2009

Zipping & Unzipping Files in iPhone

How would you zip / unzip files in your iPhone app? Well, some nice person has already implemented an objective-c class to zip and unzip. It is called "ziparchive" and you can download it from here:

http://code.google.com/p/ziparchive/


Simple to use: just call addFileToZip or UnzipFileTo.
To add this to your xcode project, import all the files then delete the files minizip.c , miniunz.c and iowin32.c & iowin32.h. Also add libz.1.2.3.dylib to frameworks. Also the top level .m file's import statements have the path included like "../..". Remove those.

Then you should be good to go.

Keep in mind though -- it can only unzip a zip format. And not all zip formats are the same.
What works for me is this --
I create a zip file using the unix command zip. This zip file can be unzipped using the ziparchive.
If you use gzip for instance, you cannot unzip it using ziparchive.


Usage of zip command in unix (on mac, open up terminal) --
zip filename_of_zip inputfile1 inputfile2 ... (or use * to say all files in directory)

alternatively,

zip -r filename directory (zips up all files inside the directory. The directory itself is not included in the zip.)

and to unzip, simply "unzip filename.zip"




-도시

No comments:

Post a Comment