Tải xuống và kéo Mục tiêu-Zip, MiniZip và ZLib kéo vào dự án của bạn từ liên kết này http://code.google.com/p/objective-zip/downloads/list (Mục tiêu-zip). nhập khẩu các tập tin: ZipFile.h, ZipException.h, FileInZipInfo.h, ZipWriteStream.h, ZipReadStream.h, zlib.h
Sử dụng mã này. Vui lòng xem bên dưới:
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];
Nguồn
2012-07-25 13:18:10
Bạn biết rằng bạn có thể tắt ARC theo từng tệp, đúng không? Vì vậy, nếu bạn có mã không phải ARC bạn thích, bạn vẫn có thể sử dụng nó trong một dự án ARC. ARC không phải là tất cả hoặc không có gì; đó là tùy chọn trình biên dịch cho mỗi tệp. http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project –
Và để làm rõ thêm, nếu bạn có dự án Xcode xây dựng một thư viện Objective-C, và nó không phải ARC, bạn có thể bao gồm dự án đó trong dự án của bạn và sử dụng thư viện, bất kể ARC của nó hay không. –
Ồ, không, tôi không biết điều đó, cổ vũ. –