Scaricare e trascinare Objective-Zip, MiniZip e ZLib trascinandoli nel progetto da questo collegamento http://code.google.com/p/objective-zip/downloads/list (Objective-zip). importare i file: ZipFile.h, ZipException.h, FileInZipInfo.h, ZipWriteStream.h, ZipReadStream.h, zlib.h
Usa questo codice. Vedere di seguito:
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];
fonte
2012-07-25 13:18:10
Sapete che è possibile disattivare ARC su base file per file, corretto? Quindi se hai un codice non ARC che ti piace, puoi ancora usarlo in un progetto ARC. ARC non è tutto-o-niente; è un'opzione per compilatore per file. http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project –
E per chiarire ulteriormente, se si dispone di un progetto Xcode che costruisce tale una libreria Objective-C, e non ARC, puoi includere quel progetto nel tuo progetto e usare la libreria, indipendentemente dal fatto che sia ARC o meno. –
Oh, no, non ne ero a conoscenza, grazie. –