如何在iOS上解压缩.zip文件?

StoreKit下载IAP内容包后,它会返回一个NSURL,如下所示:

文件://localhost/private/var/mobile/Applications/45EF2B3A-3CAB-5A44-4B4A-631A122A4299/Library/Caches/BA32BC55-55DD-3AA4-B4AC-C2A456622229.zip/

尽pipe我发现所有的消息来源都声称StoreKit在下载之后解压缩了内容包,但是却让我知道了一个ZIP文件。 这个ZIP可能包含内容包的文件结构。 但是,我如何解压缩?

使用SSZipArchive

你可以使用这个解压缩

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *outputPath = [documentsDirectory stringByAppendingPathComponent:@"/ImagesFolder"]; NSString *zipPath = Your zip file path; [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self]; 

希望它可以帮助你。

有一个伟大的第三方工具为iPhone压缩/解压缩文件

https://github.com/soffes/ssziparchive

使用非常简单。 希望帮助!

编辑:

快速的方法,我创build了需要URL,下载压缩和解压缩

 -(void)downloadAndUnzip : (NSString *)sURL_p : (NSString *)sFolderName_p { dispatch_queue_t q = dispatch_get_global_queue(0, 0); dispatch_queue_t main = dispatch_get_main_queue(); dispatch_async(q, ^{ //Path info NSURL *url = [NSURL URLWithString:sURL_p]; NSData *data = [NSData dataWithContentsOfURL:url]; NSString *fileName = [[url path] lastPathComponent]; NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName]; [data writeToFile:filePath atomically:YES]; dispatch_async(main, ^ { //Write To NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:sFolderName_p]; [SSZipArchive unzipFileAtPath:filePath toDestination:dataPath]; }); }); }