Creating a ZIP file from a folder in a document directory - Objective C (ARC)

I have an iPhone app that I developed using ARC. I have a folder containing a bunch of images in a catalog of documents that I need to fasten with mail and send via email. My project uses ARC.

Does anyone have an example of code / links to a resource that will be useful to me?

I raked on the Internet, and what I can find is incompatible with ARC - even when it claims.

+5
source share
1 answer

Objective-Zip, MiniZip ZLib http://code.google.com/p/objective-zip/downloads/list (Objective-zip). : ZipFile.h, ZipException.h, FileInZipInfo.h, ZipWriteStream.h, ZipReadStream.h, zlib.h

. . :

NSString *stringPath1 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]];
    NSString *FileName=[stringPath1 stringByAppendingPathComponent:@"Your file name"];


    NSString *stringPath=[stringPath1 stringByAppendingPathComponent:[@"Your file name" stringByAppendingFormat:@".zip"]];
    NSArray *files = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:FileName error:&error];
    ZipFile *zipFile = [[ZipFile alloc]initWithFileName:stringPath mode:ZipFileModeCreate];

    for(int i = 0;i<files.count;i++){

        id myArrayElement = [files  objectAtIndex:i];
        NSLog(@"add %@", myArrayElement);

        NSString *path = [FileName stringByAppendingPathComponent:myArrayElement];
        NSDictionary *attributes = [[NSFileManager defaultManager]attributesOfItemAtPath:path error:&error];
        NSDate *Date = [attributes objectForKey:NSFileCreationDate];

        ZipWriteStream *streem = [zipFile writeFileInZipWithName:myArrayElement fileDate:Date compressionLevel:ZipCompressionLevelBest];
        NSData *data = [NSData dataWithContentsOfFile:path];
        [streem writeData:data];
        [streem finishedWriting];
    }

    [zipFile close];
+8

All Articles