If you're searching Google for a solution to zipping and unzipping files in your app then you're likely to encounter ZipArchive first of all. However, there is a simplified version called SSZipArchive that won't throw ARC-related warnings at you when you try and run it.
Notes
- To enable the use of SSZipArchive, you first download the files from GitHub.
- Add the files from the SSZipArchive folder (i.e. SSZipArchive.m, SSZipArchive.h and the whole of the minizip folder) to your project
- Next click on the blue project file in Xcode and go to the Library and Frameworks section
- Add the libz.dylib library to your app (it is always present in Xcode, you don't need to download anything extra)
- Finally, wherever you use the SSZipArchive class remember to import the header file
EPUB Warning
If you are working with EPUB files in Xcode and want to unzip them, then dragging and dropping them into your project and doing this sort of thing:
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"MyBook" withExtension:@"epub"];
will not allow you to build a path or url to the file. Unlike the zip file where you can do this, I've found that EPUB files work best if they are situated in the Documents or Library directory, and have a path built to them using the NSFileManager class.
What to do about EPUBs
The above will mean you can't experiment with EPUBs quite so easily as zip files, but instead will likely need to add the "Open In" file handling to your app.In order to register the EPUB UTI, you need to know that the document Type is as follows:
org.idpf.epub-container
and for more information on "Open In" and registering UTIs for your app, see here.
Links
SSZipArchive (GitHub)ZipArchive (GitHub)
NSFileManager class (Apple, Developer)
What is the uniform type identifier for ePub files? (StackOverflow)
Hi! I am just getting an error saying: Reference to 'unz_file_info' is ambiguous. Any idea? Thanks!
ReplyDeleteHow can i read EPUB file in Documents?. It's seem only works with Bundle file.
ReplyDeleteYou'll need to follow the instructions under the heading "What to do about EPUBs"
Delete