2013-04-19 13 views
8

Nach StoreKit lädt das IAP Content-Paket es eine NSURL mir zurückgibt, die wie folgt aussieht:Wie entpacken Sie eine ZIP-Datei auf iOS?

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

Trotz aller Quellen, die ich behaupten, festgestellt, dass StoreKit das Content-Paket einmal heruntergeladen unzips, es reicht mir über einen ZIP. Dieser ZIP enthält wahrscheinlich die Dateistruktur des Inhaltspakets. Aber wie entzippe ich das?

+1

In der App Kauf Inhalte aus dem App Store heruntergeladen ist nicht komprimiert, so dass Sie es nicht entpacken müssen, können Sie es als ein Verzeichnis behandeln (siehe http://StackOverflow.com/a/19660668/897093) – leafcutter

Antwort

31

Verwenden SSZipArchive

Sie entpacken können mit dieser

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]; 

Hoffnung es hilft dir.

9

Es gibt ein großes 3rd-Party-Tool für Zippen/Entpacken von Dateien für iPhone

https://github.com/soffes/ssziparchive

Sehr einfach zu bedienen. Ich hoffe, das hilft!!

Edit:

Schnell Methode, die ich die URL nimmt erstellt, lädt die Zip und dekomprimiert es

-(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]; 

        }); 
}); 

} 
Verwandte Themen