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.
Ü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
@Jush, der Zip ist vorhanden und ich erstelle das Zielverzeichnis programmatisch. – onkar