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 파일은 어디에 생성됩니까? –