iOS Zip檔案解壓

2020-10-22 11:00:52

iOS Zip檔案解壓

//zip檔案解壓 資料請求回來拿到 data    使用的解壓類庫 SSZipArchive
 NSString *path;
 NSString *zipPath;
 NSArray *pathes =NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);
 //解壓過後的儲存路徑
 path= [pathes objectAtIndex:0];
 //壓縮檔案儲存的本地路徑
 zipPath= [path stringByAppendingPathComponent:@"temp.zip"];
 [data writeToFile:zipPath options:0 error:nil];
 [SSZipArchive unzipFileAtPath:zipPath toDestination:path];
 NSString *htmlpath = [path stringByAppendingPathComponent:@"test.html"];
 //轉為String
 NSString *template = [NSString stringWithContentsOfFile:htmlpath encoding:NSUTF8StringEncoding error:nil];
 NSLog(@"%@", template);