This question already has an answer here:
这个问题在这里已有答案:
- unzip source code in Iphone 2 answers
- Is there any zip decompression for iPhone? 3 answers
解压缩Iphone 2中的源代码
iPhone有拉链解压缩吗? 3个答案
After StoreKit downloads the IAP content package it returns an NSURL to me which looks like this:
在StoreKit下载IAP内容包后,它会向我返回一个NSURL,如下所示:
file://localhost/private/var/mobile/Applications/45EF2B3A-3CAB-5A44-4B4A-631A122A4299/Library/Caches/BA32BC55-55DD-3AA4-B4AC-C2A456622229.zip/
Despite all sources I found claiming that StoreKit unzips the content package once downloaded, it hands me over a ZIP. This ZIP probably contains the file structure of the content package. But how do I unzip this?
尽管我发现所有来源都声称StoreKit在下载后解压缩了内容包,但它还是通过ZIP传递给我。此ZIP可能包含内容包的文件结构。但是我如何解压缩呢?
2 个解决方案
#1
31
Use SSZipArchive
You can unzip using this
您可以使用此解压缩
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];
Hope it helps you.
希望它能帮到你。
#2
9
There is a great 3rd party tool for zipping/unzipping files for iPhone
有一个伟大的第三方工具,用于压缩/解压缩iPhone文件
https://github.com/soffes/ssziparchive
Very simple to use. Hope that helps!!
使用起来非常简单。希望有所帮助!!
Edit:
Quick method I created which takes url, downloads the zip and unzips it
我创建的快速方法,它需要url,下载zip并解压缩
-(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];
});
});
}
#1
31
Use SSZipArchive
You can unzip using this
您可以使用此解压缩
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];
Hope it helps you.
希望它能帮到你。
#2
9
There is a great 3rd party tool for zipping/unzipping files for iPhone
有一个伟大的第三方工具,用于压缩/解压缩iPhone文件
https://github.com/soffes/ssziparchive
Very simple to use. Hope that helps!!
使用起来非常简单。希望有所帮助!!
Edit:
Quick method I created which takes url, downloads the zip and unzips it
我创建的快速方法,它需要url,下载zip并解压缩
-(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];
});
});
}