0
NSLOGをすべてテキストファイルに書き込み、テーブルビューのセルをクリックするとそのファイルをサーバに送信します。 NSURLConnectionを使用して投稿する前に、テキストファイルをzipファイルに変換します。しかし、Zipファイルの中にはいくつかのゴミデータがありますが、テキストファイルには正しい内容があります。私はSSZipArchive、私はファイルを投稿するために使用するコードは、どのような援助が大きな助けになるでしょうiOSでZipファイルが正しく作成されていません
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Logger.txt"]];
NSString* zipfile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"Logger.zip"]];
//create zip file, return true on success
BOOL isZipCreated=[SSZipArchive createZipFileAtPath:zipfile withContentsOfDirectory:logFilePath];
if (isZipCreated) {
NSLog(@"Zip file Created at Path : %@",zipfile);
NSString *contentOfZipFile = [NSString stringWithContentsOfFile:zipfile encoding:NSUTF8StringEncoding error:NULL];
NSData *zipData = [contentOfZipFile dataUsingEncoding:NSUTF8StringEncoding];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[zipData length]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:finalURL]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/zip" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:zipData ];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
}
else {
NSLog(@"Zip create error");
}
あるを使用しています。
このライブラリをインストールするために必要なことを説明できますか? –
プロジェクトにポッドを追加して、githubリンクで説明した手順に従うこともできます。 https://github.com/gianlucabertani/Objective-Zip –
zipファイルはどこに作成されますか? –