How to unzip a zip file on iOS?

After StoreKit downloads the IAP content package, it returns me an NSURL that looks like this:

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

Despite all the sources, I found that StoreKit unpacks the content package after downloading it, it passes me a ZIP. This ZIP probably contains the file structure of the content package. But how can I unzip this?

+8
ios objective-c iphone storekit in-app-purchase
source share
2 answers

Use SSZipArchive

You can unzip 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 this helps you.

+31
source share

There is a great third-party file unzip / unzip tool for iPhone

https://github.com/soffes/ssziparchive

Very easy to use. Hope this helps!

Edit:

The quick method I created that takes the url loads the zip code and unpacks it

 -(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]; }); }); } 
+9
source share

All Articles