上傳文件,上傳圖片理想的狀態(tài)就是壓縮好了再丟給服務端,所以壓縮很重要。
我用的是SSZipArchive壓縮,今天不講怎樣壓,很簡單,介紹接入的文章一抓一大把,今天主要說兩個點(自己遇到的問題)
1.壓縮后的文件打不開,顯示解壓錯誤
2.壓縮后找不到文件?
解決方案:??源文件和壓縮后的文件名要保持一致,下文代碼中的@"Log.txt"和@"Log.zip"一致(撇開后綴名)
? ? ? ? ? ? ?//源文件
?? ? ? ? ? ? NSString *myLogPath =[rootLogPath stringByAppendingPathComponent:@"Log.txt"];;
? ? ? ? ? ? //壓縮文件名
? ? ? ? ? ? NSString *zipFileName =[rootLogPath stringByAppendingPathComponent:@"Log.zip"];
? ? ? ? ? ? //壓縮的文件
? ? ? ? ? ? NSArray *fileNamearr = @[myLogPath];
? ? ? ? ? ?//壓縮
? ? ? ? ? ? BOOL isSuccess =[SSZipArchive createZipFileAtPath:zipFileName withFilesAtPaths:fileNamearr];
? ? ? ? ? ? if(isSuccess){
? ? ? ? ? ? ? ? NSLog(@"log壓縮成功");
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? NSLog(@"log壓縮失敗");
? ? ? ? ? ? }