5

私はARCを使って開発したiPhoneアプリケーションを持っています。私はzipと電子メールする必要がある私のドキュメントディレクトリに画像のヒープを含むフォルダがあります。私のプロジェクトは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ではない場合でも、そのプロジェクトをプロジェクトに組み込み、ライブラリを使用することができます。 –

+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 –

関連する問題