5

ARC를 사용하여 개발 한 iPhone 응용 프로그램이 있습니다. 내 문서 디렉토리에 우편 번호와 전자 메일이 필요한 이미지 힙이 들어있는 폴더가 있습니다. 내 프로젝트는 ARC를 사용합니다.문서 디렉토리의 폴더에서 ZIP 파일 만들기 - Objective C (ARC)

나에게 도움이 될만한 리소스에 대한 예제 코드/링크가있는 사람이 있습니까?

나는 온라인으로 주위를 긁어 모아 내가 찾을 수있는 것은 ARC와 호환되지 않습니다 봤는데 -이 주장에도.

+6

ARC를 파일 단위로 해제 할 수 있다는 것을 알고 계시겠습니까? 따라서 ARC가 아닌 코드가있는 경우 ARC 프로젝트에서이 코드를 사용할 수 있습니다. ARC는 전부 또는 일부가 아닙니다. 이것은 파일 당 컴파일러 옵션입니다. http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project –

+0

그리고 더 명확히하기 위해, 그러한 빌드를하는 Xcode 프로젝트가 있다면 Objective-C 라이브러리 및 ARC가 아닌 라이브러리를 사용하면 해당 프로젝트를 프로젝트에 포함하고 ARC 여부와 관계없이 라이브러리를 사용할 수 있습니다. –

+0

오, 아니, 나는 그 사실을 몰랐다. –

답변

8

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]; 
+0

죄송합니다. 제공하신 링크는 지금 죽었습니다. – mcy

+0

죄송하지만 1 년 전이었습니다 ... –

+2

이 프로젝트에 대한 유효한 링크 : https://github.com/flyingdolphinstudio/Objective-Zip을 찾았습니다. –