我有一个文本文件,我在其中编写所有NSLOG,并在需要时将其发布到服务器。由于我想优化发送到服务器的文件的大小,我想压缩文本文件。我提到了很多例子,但不能清楚地理解。这是我创建文件的代码如何压缩文本文件并使用NSURLConnection在objective-c
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"Logger.txt"];
NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
freopen([logFilePath cStringUsingEncoding:NSUTF8StringEncoding],"a+",stderr);
并且这是将文件发布到服务器的代码。
NSString *finalURL = [self getSupportServletURL:persist];
NSURL *url = [NSURL URLWithString:finalURL];
NSMutableURLRequest * requests = [[NSMutableURLRequest alloc]initWithURL:url];
[requests setHTTPMethod:@"POST"];
[requests setValue:@"text" forHTTPHeaderField:@"Content-type"];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"Logger.txt"];
NSString *content = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:NULL];
LogInfo(@"Data being posted to server %@",finalURL);
LogTrace(@"Post Data : Data being posted to server \n%@",content);
[requests setTimeoutInterval:60.0];
[requests setHTTPBody:[content dataUsingEncoding:NSUTF8StringEncoding]];
[requests setValue:[NSString stringWithFormat:@"%lu",(unsigned long)[content length]] forHTTPHeaderField:@"Content-Length"];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:requests delegate:self];
并且这个效果很好。任何人都可以帮助我将其转换为zip文件(包括需要包含在.m文件中的东西),并将其发布到服务器。先谢谢你。
看看[这里](https://github.com/ZipArchive/ZipArchive)库。 – Mahesh
我有大量的例子像这些@mahesh,但我不清楚标题包含和东西..所以你可以解释,如果它是可能的? –