- Download ZipArchive from http://code.google.com/p/ziparchive/downloads/list.
- Drag into project.
- Add to project existing framework libz.1.2.3.dylib (last version).
- Import to project:
#import "ZipArchive.h"
- Uncompress zip file example:
NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"myZipFileName.zip"]; NSString *output = [documentsDirectory stringByAppendingPathComponent:@"unZipDirName"]; ZipArchive* za = [[ZipArchive alloc] init]; if( [za UnzipOpenFile:zipFilePath] ) { if( [za UnzipFileTo:output overWrite:YES] != NO ) { //unzip data success //do something } [za UnzipCloseFile]; } [za release];
- Compress directory or file example:
BOOL isDir=NO; NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSArray *subpaths; NSString *toCompress = [NSString stringWithString:@"dirToZip_OR_fileNameToZip"]; NSString *pathToCompress = [documentsDirectory stringByAppendingPathComponent:toCompress]; NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:pathToCompress isDirectory:&isDir] && isDir){ subpaths = [fileManager subpathsAtPath:pathToCompress]; } else if ([fileManager fileExistsAtPath:pathToCompress]) { subpaths = [NSArray arrayWithObject:pathToCompress]; } NSString *zipFilePath = [documentsDirectory stringByAppendingPathComponent:@"myZipFileName.zip"]; ZipArchive *za = [[ZipArchive alloc] init]; [za CreateZipFile2:zipFilePath]; if (isDir) { for(NSString *path in subpaths){ NSString *fullPath = [pathToCompress stringByAppendingPathComponent:path]; if([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && !isDir){ [za addFileToZip:fullPath newname:path]; } } } else { [za addFileToZip:pathToCompress newname:toCompress]; } BOOL successCompressing = [archiver CloseZipFile2];
Zip/Unzip files on iPhone/iPad/iOS
Ярлыки:
compress,
iOS,
iPad,
iPhone,
objective C,
uncompress,
unzip,
zip,
ZipArchive
Subscribe to:
Post Comments (Atom)
Thanks you sir,
ReplyDeleteIt helped me a lot.
_MS
great job, thanks!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHello everyone, I'm sviluppadso an application for iPad using xcode4.2. Using these instructions I am to have this error
DeleteUndefined symbols for architecture i386:
"_OBJC_CLASS_ $ _ZipArchive", Referenced from:
objc-class-ref in MainView.o
ld: symbol (s) not found for architecture i386
Can you help me pls do not know how to do ...
please note that I am using the version libz1.2.5 the last exit and development for ios 5.1
When you drag the ZipArchive folder into your project, you have to choose "Create groups for any added folders" and not "Create folder references for any added folders."
Deletegreat tutorial helped me a lot
ReplyDeletethanks a ton...
ReplyDeleteI can't make this work today. Lots of errors. maybe because xcode version 7.x.x
ReplyDelete