Meine App-Downloads von Dateien aus dem Internet und speichert sie NSFileManager
alles mit scheint, bis ich die App xCode zu arbeiten erneut aus (ich die Dateien nicht verwenden können, entfernen Sie diese -....)Warum funktioniert NSFileManager nicht ordnungsgemäß?
Aber wenn ich Ich habe es nicht mit xCode erneut ausgeführt und es normalerweise auf meinem Telefon verwendet, scheint dieses Problem nicht zu haben. (Beispiel: kann ich die heruntergeladene MP3 spielen)
Hier einige Code von meinem Projekt ist
// Creates a new path for the download
func createFilePathForDownload(filePath: String) -> NSURL? {
let searchForDoucumentDirectory = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
let documentDirectory = searchForDoucumentDirectory.first
return documentDirectory!.URLByAppendingPathComponent(filePath)
}
// After the download is done downloading this NSURLSessionDownloadTaskDelegate method will excute
func URLSession(session: NSURLSession, downloadTask: NSURLSessionDownloadTask, didFinishDownloadingToURL location: NSURL) {
for (_, downloadInProgress) in allDownloads.enumerate() {
if downloadTask.isEqual(downloadInProgress.downloadTask) {
let newPath = createFilePathForDownload((downloadInProgress.downloadTask.response?.suggestedFilename!)!)
downloadInProgress.filePathTemp = location
downloadInProgress.filePath = newPath
if (NSFileManager.defaultManager().fileExistsAtPath(location.path!) == true) {
print("\(location.path!) does exist")
}
do {
try NSFileManager.defaultManager().copyItemAtURL(location, toURL: downloadInProgress.filePath)
} catch {
}
do {
try NSFileManager.defaultManager().removeItemAtURL(location)
} catch {
}
if (NSFileManager.defaultManager().fileExistsAtPath(downloadInProgress.filePath.path!) == true) {
print("\(downloadInProgress.filePath.path!) does exist")
}
downloadInProgress.downloadData = nil
downloadInProgress.downloadStatus = DownloadStatus.Finished
delegate?.downloadHasBeenFinished!(downloadInProgress)
saveChanges()
}
}
}
mit so etwas wie dies
func playMediaAtPath(path: NSURL) {
let player = AVPlayer(URL: path)
self.moviePlayer.player = player
self.presentViewController(self.moviePlayer, animated: true) {
self.moviePlayer.player?.play()
}
}
Die App Größe und Leistung zeigen nicht, dass die Dateien sind noch vorhanden, aber nicht geöffnet.
/private/var/mobile/Containers/Data/Application/4B5BE8F6-C71A-4BDC-86E5-3132AD9330B8/tmp/CFNetworkDownload_5rFN0V.tmp tut
/var/mobile/Behälter/Daten/Anwendung existieren/4B5BE8F6-C71A-4BDC-86E5-3132AD9330B8/Dokument/OneRepublic - überall dort, wo ich Go.mp3
NSLog Dokument Pfad beim Ausführen und erneut ausgeführt und vergleichen, wenn sie gleich sind zu sehen. – NeverHopeless