2016-04-25 8 views
1

Ich habe Dateien herunterladen um didFinishDownloadingToURL: und ich möchte es entpacken. Meine aktuellen Code sieht wie folgt aus:iOS - NSURLSessionTask entpacken Datei heruntergeladen

- (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location 
{ 
    for(NSMutableDictionary *downloadInfo in downloadingArray) 
    { 
     if([[downloadInfo objectForKey:kMZDownloadKeyTask] isEqual:downloadTask]) 
     { 
      if (location) 
      { 
       NSString *srcPath = location.absoluteString; 
       NSString *fullPathDst = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 

       //unzip 
       ZipArchive *zipArchive = [[ZipArchive alloc] init]; 
       [zipArchive UnzipOpenFile:srcPath Password:@"pasword"]; 
       [zipArchive UnzipFileTo:fullPathDst overWrite:YES]; 
       [zipArchive UnzipCloseFile]; 

       NSFileManager *fileManager = [NSFileManager defaultManager]; 
       NSError *error; 
       NSArray *files = [fileManager contentsOfDirectoryAtPath:fullPathDst error:&error]; 

       NSLog(@"files: %@", files); 
      } 

      break; 
     } 
    } 
} 

die files Array leer ist. Was mache ich falsch?

Antwort

0

Sie nicht absoluteString verwenden sollten, als dass ein Schema enthält (z file://). Verwenden Sie stattdessen die Methode path.

0

Sie haben nicht die Dateinamen und Dateityp geschrieben: -

NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ZipFileName" ofType:@"zip"]; 
0

Der unzipping einen Ordner im Dokumentenverzeichnis würde erstellen, die die Dateien enthalten würden. Bitte überprüfen Sie, dass

NSString *zipPath = [[NSBundle mainBundle] pathForResource:zipFileName ofType:@"zip"]; 
NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath]; 

Get Zip-Datei aus Dokumenten Verzeichnis: -

NSString *filename = @"MyZipFile.zip"; 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0]; 
NSString * zipPath = [documentsDirectory stringByAppendingPathComponent:filename]; 

NSString *destinationPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
[SSZipArchive unzipFileAtPath:zipPath toDestination:destinationPath]; 
Verwandte Themen