由于項(xiàng)目里面需要軌跡點(diǎn)經(jīng)緯度太多,上傳比較慢奢入,所以用文件保存然后壓縮之后再上傳尔破。顯示的時(shí)候需要解壓然后讀取顯示肄梨。
https://github.com/ZipArchive/ZipArchive
這個(gè)是第三方的壓縮解壓框架键科。
1壓縮
這個(gè)是宏
#define doc_path(_fileOrFolder_) [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:_fileOrFolder_]
//保存內(nèi)容的文件text文件
NSString *path = doc_path(@"pointfile.txt");
NSMutableString *setStr=[[NSMutableString alloc]init];
for (int i=0;i<[pointss count];i++) {
CLLocation *cllocation=pointss[i];
NSString *str=[NSString stringWithFormat:@"%.5f,%.5f\n",cllocation.coordinate.longitude,cllocation.coordinate.latitude];
[setStr appendString:str];
}
NSString *str=setStr;
[str? writeToFile:path? atomically:YES encoding:NSUTF8StringEncoding error:nil];//寫內(nèi)容到文件里面
NSString *zippath = doc_path(@"zipfile.zip");//創(chuàng)建壓縮文件路徑
ZipArchive *za = [[ZipArchive alloc] init];//第三方壓縮類
[za CreateZipFile2:zippath];//創(chuàng)建壓縮文件
[za addFileToZip:path newname:@"zipfilepoint.txt"];//增加內(nèi)容到壓縮文件
BOOL success = [za CloseZipFile2];//關(guān)閉
2解壓
如果是解壓的話看是本地解壓闻丑,還是從服務(wù)器下載然后解壓。我的是從服務(wù)器下載然后解壓萝嘁。下載之后保存到本地然后解壓梆掸。
NSString *FilePath = doc_cache_path(@"guiji.zip");
NSString *getpath = doc_cache_path(@"fileguiji");//解壓到這個(gè)路徑下面
NSData *data = entity;//這是服務(wù)器返回的數(shù)據(jù)
[data writeToFile:FilePath atomically:YES];//然后寫到FilePath目錄下面
ZipArchive* zipFile = [[ZipArchive alloc] init];
[zipFile UnzipOpenFile:FilePath];
[zipFile UnzipFileTo:getpath overWrite:YES];
[zipFile UnzipCloseFile];