2016-06-01 3 views
3

Ich verwende SSZipArchive, um den Inhalt der Datei zu extrahieren, die ich aus dem Internet herunterladen und in Documents speichern. Die Ressourcen, die ich herunterlade, sind in Form von Zip-Dateien, die ich nach erfolgreichem Download entpacken werde.Entpacken Sie eine Datei mit SSZipArchive extrahiert nicht den Inhalt der Datei

@IBAction func downloadData(sender: UIButton) 
{  if let myAudioDataFromUrl = NSData(contentsOfURL: audioUrl){ 
       // after downloading your data you need to save it to your destination url 
       if myAudioDataFromUrl.writeToURL(destinationUrl, atomically: true) { 
        print("file saved") 
        printTimestamp() 
        let folderName = "Aspire Brochure"//audioUrl.lastPathComponent!.stringByReplacingOccurrencesOfString(".zip", withString: "") 
        let destination = documentsUrl.URLByAppendingPathComponent(folderName) 
        let fileManager = NSFileManager.defaultManager() 
        print("This is the folderName \(destinationUrl)") 
        print("This is the destination \(destination)") 
        let success = fileManager.fileExistsAtPath(destination.absoluteString) as Bool 
        if success == false { 
         do { 
          print("it is here") 
          try! fileManager.createDirectoryAtPath(destination.absoluteString.stringByReplacingOccurrencesOfString("file://", withString: ""), withIntermediateDirectories: true, attributes: nil) 
          print("it hascome here ") 
         } 
        } 
       // let success = fileManager.fileExistsAtPath(destPath) as Bool 
        print("trying to unzip the file") 

        //let fileManager = NSFileManager.defaultManager() 
        let checkFile = NSFileManager.defaultManager().fileExistsAtPath(destination.absoluteString.stringByReplacingOccurrencesOfString("file://", withString: "")) 
        print("this is the check value response \(checkFile)") 
        var tmp = SSZipArchive.unzipFileAtPath(destinationUrl.absoluteString, toDestination: destination.absoluteString) 
        //var tmp = SSZipArchive.unzipFileAtPath(destination.absoluteString.stringByReplacingOccurrencesOfString("file://", withString: ""), toDestination: destination.absoluteString) 
        print("unzipped the file \(tmp)") 

        } else { 
         print("error saving file") 
        } 
       } 
      } 

Die Datei wird erstellt, es wird jedoch nichts in sie extrahiert.

+0

Überprüfen Sie Ihren Zielpfad und Download-Pfad. SSZipArchive.unzipFileAtPath würde false zurückgeben, wenn die Datei nicht im angegebenen Pfad gefunden wird. – Jush

+0

@Jush, der Zip ist vorhanden und ich erstelle das Zielverzeichnis programmatisch. – onkar

Antwort

4

Ran in das heute dauerte mich ein paar Stunden, um es herauszufinden. SSZipArchive gibt false zurück, wenn es die Zip-Datei nicht finden kann. Dies geschieht wahrscheinlich, weil die URL, die Sie zurückgeben, eine [NSURL absoluteString]; ist, die file:// am Anfang hat. Rufen Sie einfach [NSURL path]; auf der URL und es sollte funktionieren

+0

Wow, so eine einfache Lösung; Danke!! Würde das zweimal ankreuzen, wenn ich könnte! – user3069232

+0

Wow, du hast gerade meinen Tag gemacht. – tentmaking

Verwandte Themen